No enclosing instance of type is accessible. [duplicate] No enclosing instance of type is accessible. [duplicate] multithreading multithreading

No enclosing instance of type is accessible. [duplicate]


If you change class MyThread to be static, you eliminate the problem:

public static final class MyThread implements Runnable

Since your main() method is static, you can't rely on non-static types or fields of the enclosing class without first creating an instance of the enclosing class. Better, though, is to not even need such access, which is accomplished by making the class in question static.


Since MyThread is an inner class you have to access it using an instance of MyThreadTest:

public static void main(String args[]) {    MyThreadTest test = new MyThreadTest();    new Thread(test.new MyThread(new Integer(1),test)).start();}