Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
680 views
in Technique[技术] by (71.8m points)

java - implicit super constructor object() is undefined. must explicitly invoke another constructor

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

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 click Add Library.
  • Select JRE System Library click Next
  • Then select JRE from options as per your requirement. Click Finish

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...