No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing
instance of type Outer (e.g. x.new A() where x is an instance of Outer).
-
class Outer {
-
class Inner {
-
}
-
public static void foo() {
-
new Inner();
-
}
-
public void bar() {
-
new Inner();
-
}
-
public static void main(String[] args) {
-
new Inner();
-
}
-
}
错误显示:没有可访问的内部类的实例,必须分配一个合适的内部类的实例
错误原因:非静态内部类方法不能被静态内部类调用,必须修饰为静态类才可以
解决方法:将内部类修饰为static
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30046312/viewspace-2143543/
,如需转载,请注明出处,否则将追究法律责任。