No enclosing instance of type * is accessible.

来源:互联网 发布:软件设计师好过吗 编辑:程序博客网 时间:2024/06/04 19:32

这是我项目中遇到的问题:


报错内容:No enclosing instance of type * is accessible. Must qualify the allocation with an enclosing instance of type * (e.g. x.new A() where x is an instance of  * ).


class 直接写的是动态的内部类,可是主程序是public static void main。 (静态类)
Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。 
所以,最简单的解决办法是为 class  添加修饰 static ,使其为静态内部类 static class

问题就得到了解决

0 0