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

来源:互联网 发布:淘宝一个宝贝多个价格 编辑:程序博客网 时间:2024/05/22 06:54

错误提示:No enclosing instance of type Monster is accessible. Must qualify the allocation with an enclosing instance of type Monster (e.g. x.new A() where x is an instance of Monster).


于是百度谷歌了一下相关资料。原来我写的内部类是动态的,也就是开头以public class开头。而主程序是public static class main。在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。所以解决办法是将public class改为public static class.