隐式超构造函数object()未定义。必须显式调用另一个构造函数 [英] implicit super constructor object() is undefined. must explicitly invoke another constructor
问题描述
object()
构造函数。这是课程: package com.my.ok;
public class First {
}
编辑:
我发现如果我将执行环境
设置为 javaSE -1.7
如果您的 JRE
不是,则会出现此问题在项目内建路径中配置。
配置 JRE:
在Eclipse中
- 右键单击在您的项目中,选择
构建路径
- >配置构建路径
- 转到到
库选项卡
单击添加库
。 - 选择
JRE系统库
单击下一步
- 然后选择
JRE
根据您的要求从选项。点击完成
在Netbeans中: p>
- 右键单击项目,然后选择
属性
。 - 在库类别中,根据您的要求选择
Java Platform
。 - 然后转到源类别选择
源/二进制格式
,并根据您的要求选择JDK。
说明:
错误是因为您没有将系统库您的项目和您的类无法在创建对象时找到层次结构中首先调用的 Object()
构造函数。
示例:
package com.my.ok;
public class First {
}
发生什么是编译器
默认扩展您的第一个
类到对象
class
package com.my.ok;
public class First extends Object {
}
但 Object
在您的案例中找不到类,您收到此错误。
Is this a new bug? I got a new mac computer and install eclipse on it. The checksum matches fine. But when I try to create a simple class, just for basic testing, I get the error mentioned in the title. Never before have I seen java complaining about object()
constructor. Here is the class:
package com.my.ok;
public class First {
}
EDIT:
I am finding that the problem happens if I set execution environment
to javaSE-1.7
This problem occurs if your JRE
is not configured in project built path.
To configure JRE:
In Eclipse:
- Right click on your project and select
Build Path
->Configure Build Path
- Go to
Libraries tab
clickAdd Library
. - Select
JRE System Library
clickNext
- Then select
JRE
from options as per your requirement. ClickFinish
In Netbeans:
- Right Click on the Project and select
Properties
. - In the Library category select
Java Platform
as per your requirement. - Then go to Source category select
Source/Binary Format
and select JDK as per your requirement.
Explanation:
The error was because you did not include System libraries in your project and your class was not able to find Object()
constructor which is called first in the hierarchy when you create an object.
Example:
package com.my.ok;
public class First {
}
what happens is compiler
extends by default your First
class to Object
class
package com.my.ok;
public class First extends Object {
}
but Object
class was not found in your case and you were getting this error.
这篇关于隐式超构造函数object()未定义。必须显式调用另一个构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!