在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.csdn.net/qq_41885010/article/details/80516284
https://www.cnblogs.com/runnigwolf/p/5570810.html

相关文章:

  • 2021-08-15
  • 2021-09-08
  • 2022-12-23
  • 2022-01-01
  • 2022-01-23
  • 2021-08-05
  • 2022-02-03
猜你喜欢
  • 2022-12-23
  • 2021-06-02
  • 2021-07-24
  • 2021-05-24
  • 2021-08-16
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案