Recently in Java, when compiling an example of writing a book, because the code is only part of the book, so he complements an internal class. The result appears at compile time: No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instance of type E (e.g. X.new A () where x is an instance of E). E refers to the inner class that I wrote.
As a hint, there is no instance of an accessible inner class E that must be assigned an instance of an appropriate inner class E (such as X.new A () and x must be an instance of E. look at this hint, I wonder, I have used new instantiation of this class, why not yet.
So Baidu Google a bit of relevant information. Originally I wrote the inner class is dynamic, that is, the beginning of the public class start. and the main program is public static class main. In Java, a static method in a class cannot invoke a dynamic method directly. Only an inner class is decorated as a static class, and then the member variables and member methods of the class can be called in a static class. So the solution is to change the public class to public static class.
Write down this question here, also on the side of the same problem of friends check
java-error-no enclosing instance of type E is accessible