No enclosing instance of type xxx.class(你的类) is accessible. Must qualify the allocation with an enclosing instance of type xxx.class(你的类) (e.g. x.new A() where x is an instance of xxx.class(你的类)).
出现以上错误的原因:
public class One{
public static void main(String []args){
Two mTwo= new Two();
}
class Two{
}
}
注意你以上的方括号,在类One中,是包括Two类的,所以会出现以上的报错。
解决方法为:
public class One{
public static void main(String []args){
Two mTwo = new Two();
}
}
class Two{
}
把Two移除One类即可。

本文介绍了一种常见的Java编程错误——无法从外部类访问内部类实例的情况,并提供了解决方案。通过调整类的结构,可以有效避免此类错误。
1300

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



