Which is the Best Java Web Framework ?

ERROR - No enclosing instance of type is accessible. Must qualify the allocation with an enclosing instance of type (e.g. x.new A() where x is an instance of )

Error

No enclosing instance of type <ClassName> is accessible. Must qualify the allocation with an enclosing instance of type <ClassName> (e.g. x.new A() where x is an instance of <ClassName>).

Error Type

Compilation


Cause

Trying to initialize the instance of inner class without specifying the instance of outer class. Inner classes are not accessible directly using the Outer class name as only static inner classes are accessible that way.


Sample Code

public class OuterClass {

     public class InnerClass {
     }


OuterClass.InnerClass = new OuterClass.InnerClass(); // this line gives error

Resolution

Either make the inner class as static inner class

public class OuterClass {

     public static class InnerClass {
     }


OuterClass.InnerClass = new OuterClass.InnerClass(); 

But with this, the copy of the inner class will not be object specific but class specific


Or 

Initialize the Inner class using the Outer class instance

public class OuterClass {

     public class InnerClass {
     }


OuterClass.InnerClass = new OuterClass.new InnerClass(); 




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.