在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a

在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a
错误原因:No enclosing instance of type ooo is accessible. Must qualify the allocation with an enclosing instance of type ooo (e.g. x.new A() where x is an instance of ooo).

方法
方法一:分为两个class 不用内部类

方法二:给内部类加个static,因为main方法是静态的。

在一个类的静态成员中去访问非静态成员之所以会出错是因为在类的非静态成员不存在的时候静态成员就已经存在了,访问一个内存中不存在的东西当然会出错。

在main函数中创建新对象时出错 No enclosing instance of type ooo is accessible. Must qualify the allocation with a

可以参看博客:https://blog.****.net/qq_41885010/article/details/80516284
https://www.cnblogs.com/runnigwolf/p/5570810.html