No enclosing instance of type E is accessible Must qualify the allocation with an enclosing
Original text: http://blog.csdn.net/sunny2038/article/details/6926079
Recently, I was looking at Java. When compiling an example in the book, because there was only part of the code in the book, I added an internal class myself. Result: 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 I wrote.
According to the prompt, if there is no accessible instance of inner class E, an appropriate instance of inner class E must be allocated (e.g. X.New a(), X must be an instance of E.) Looking at this prompt, I wonder why I have instantiated this class with new.
So Baidu googled the relevant information. Originally, the internal class I wrote is dynamic, that is, it starts with public class. The main program is public static class main. In Java, static methods in classes cannot call dynamic methods directly. Only if an internal class is modified to a static class, then the member variable and member method of the class can be invoked in a static class. Therefore, the simplest solution is to change public class to public static class
Write down this problem here, and check it with friends who encounter the same problem.
Internal class: http://www.cnblogs.com/chenssy/p/3388487.html