Compiler Error J0261

An explicit enclosing instance of class 'identifier' is needed to instantiate inner class 'identifier'

The compiler detected an attempt to create an instance of an inner class without specifying an instance of its enclosing class. This error usually occurs when an attempt is made, within a static method, to instantiate an inner class as you would an outer class. To create an instance of an inner class, you must use an existing instance of its outer class. Create an instance of the enclosing class and use it to instantiate the inner class and compile again.

The following example illustrates this error:

public class Simple{
   class InnerClass{
      //do something here
   }
   
   public static void main(String args[]){
      InnerClass inc = new InnerClass();
      /*error: an instance of the outer class is required to instantiate
               its inner class */
   }
}

The following example illustrates how to create an instance of an inner class using an instance of its outer class:

public class Simple{
   class InnerClass{
      //Do something here
   }
   public static void main(String args[]){
      Simple smp = new Simple();
      /*use the instance of 'Simple' to create an instance of its inner
        class*/
      InnerClass inc = smp.new InnerClass();
   }
}