java出现No enclosing instance of type main is accessible. Must qualify the allocation with an enclosin

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java出现No enclosing instance of type main is accessible. Must qualify the allocation with an enclosin相关的知识,希望对你有一定的参考价值。

根据提示,没有可访问的内部类E的实例,必须分配一个合适的内部类E的实例(如x.new A(),x必须是E的实例。)看着这句提示,我就纳闷了,我已经用new实例化了这个类,为什么还不行呢。原来我写的内部类是动态的,也就是开头以public class开头。而主程序是public static class main。在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。所以不做其他变动的情况下,最简单的解决办法是将public class改为public static class.

以上是关于java出现No enclosing instance of type main is accessible. Must qualify the allocation with an enclosin的主要内容,如果未能解决你的问题,请参考以下文章

java出现No enclosing instance of type main is accessible. Must qualify the allocation with an enclosin

No Enclosing instance ...的原因和解决方法

No enclosing instance of type test is accessible. Must qualify the allocation with an enclosing inst

Java中报错No enclosing instance of type caiquan is accessible. Must qualify the allocation with an encl

No enclosing instance of type XXX is accessible

No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing