Private inner & Runnable class instantiation failure
// What is wrong this code?
public class PingPong
{
...
public static void main(String[] args)
{
PingPong application = new PingPong(args);
Thread t1 = new Thread(new WaitTask());
Thread t2 = new Thread(new SocketTask());
t1.start();
t2.start();
}
class WaitTask implements Runnable
{
public WaitTask()
{}
public void run()
{}
}
class SocketTask implements Runnable
{
public SocketTask()
{}
public void run()
{}
}
}
Eclipse says:
No enclosing instance of type PingPong is accessible. Must qualify the allocation with an enclosing instance of type PingPong (e.g. x.new A() where x is an instance of PingPong).
and compilation gives:
C:\Data\workspace\ApplAndServ\src>javac PingPong.java
PingPong.java:130: non-static variable this cannot be referenced from a static context
Thread t1 = new Thread(new WaitTask());
^
PingPong.java:131: non-static variable this cannot be referenced from a static context
Thread t2 = new Thread(new SocketTask());
^
2 errors