No enclosing instance of type xx is accessible. Must qualify the allocation with an enclosing instance of type xx (e.g. x.new A() where x is an instance of xx ).
这种情况一般是在调用内部类(未被静态修饰)时出现,两种解决方法:
1、直接Inner in = new Outer().new Inner();
2、加static修饰 ,Inner in = new Inner();
例子:https://stackoverflow.com/questions/7841210/having-a-issue-using-inner-class-java

--> java编程思想: P193
本文探讨了在Java中调用未被静态修饰的内部类时遇到的No enclosing instance of type xx is accessible错误。提供了两种解决方案:一是通过创建外部类实例再调用内部类;二是将内部类声明为静态。附带示例链接,深入理解Java编程思想。
1万+

被折叠的 条评论
为什么被折叠?



