在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方法是静态的。


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



可以参看博客:https://blog.csdn.net/qq_41885010/article/details/80516284

https://www.cnblogs.com/runnigwolf/p/5570810.html



相关文章
|
7月前
|
Java Android开发 Kotlin
@JvmDefault is only supported since JVM target 1.8. Recompile with '-jvm-target 1.8’
@JvmDefault is only supported since JVM target 1.8. Recompile with '-jvm-target 1.8’
49 5
|
JavaScript
vue 渲染列表报错Avoid using non-primitive value as key, use string/number value instead. found in
vue 渲染列表报错Avoid using non-primitive value as key, use string/number value instead. found in
103 0
对‘avformat_find_stream_info’未定义的引用、to the PKG_CONFIG_PATH environment variable
对‘avformat_find_stream_info’未定义的引用、to the PKG_CONFIG_PATH environment variable
94 0
解决办法:找不到g_type_check_instance_cast
解决办法:找不到g_type_check_instance_cast
172 0
|
Linux
解决办法:error: <item> inner element must either be a resource reference or empty.
解决办法:error: <item> inner element must either be a resource reference or empty.
237 0
|
Java C++
程序运行问题排查和解决:an instance of ‘std::logic_error‘what(): basic_string::_M_construct null not valid
程序运行问题排查和解决:an instance of ‘std::logic_error‘what(): basic_string::_M_construct null not valid
1978 0
|
C++
Effective C++学习笔记之copy构造函数和default函数和copy赋值函数(operator=)
Effective C++学习笔记之copy构造函数和default函数和copy赋值函数(operator=)
149 0

热门文章

最新文章