55

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

Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87
  • 2
    Sounds like an installation problem. The code is obviously fine. – Jon Skeet Jun 21 '13 at 17:07
  • 1
    http://stackoverflow.com/questions/14466323/gson-serialized-name-implicit-super-constructor-object-is-undefined-for-defa Is this similar to the question? – zw324 Jun 21 '13 at 17:08
  • 2
    Reinstall everything. – Steve P. Jun 21 '13 at 17:14
  • @ZiyaoWei Not quite. But thanks for the link. I have used the notes there for some research. – Cote Mounyo Jun 21 '13 at 17:19
  • 1
    I am finding that the problem happens if I set `execution environment` to `javaSE-1.7`. I will edit to add image, in case it's necessary. – Cote Mounyo Jun 21 '13 at 17:26
  • 2
    Yes, sounds like a eclipse can't find a valid JRE. In eclipse preferences/java/installed JREs, check that you have the directory of a valid JRE. You can verify by using the shell to cd to that directory, and run bin/javac against your source file. If you get the same result there, reinstall java. – Tap Jun 21 '13 at 17:35

6 Answers6

154

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.

Vishrant
  • 15,456
  • 11
  • 71
  • 120
  • 1
    To me, this happened when updating Eclipse/ADT add-ons. I have JRE 1.7 installed and after the update (it seems) I must select '1.7' as compliance level in the Window>Preferences>Java>Compiler (likely installing Java 1.6 JRE would also suffice). There's a small warning signal in that dialog, but no route from the actual error messages to there.. SO saved the day, Once More! (btw, interestingly the project specific compliance level seems to be just fine, remaining as 1.6) – akauppi Mar 05 '14 at 10:53
  • 1
    Thanks a lot +1 for the answer. – Shailendra Madda Jun 07 '15 at 14:51
  • not sure what happened but deleting my project and recreating it solved this for me – fIwJlxSzApHEZIl Jan 07 '16 at 06:14
  • @advocate its because when you created new project, JDK was added, you can check it in project properties -> build path -> libraries – Vishrant Jan 07 '16 at 09:49
  • For those who end up here without any GUI and for example are just using the `eclipse.jdt.ls`. The fix is to set the `JAVA_HOME` appropriately. For example on macOS: `export JAVA_HOME=$(/usr/libexec/java_home)`. – terje Nov 11 '18 at 20:10
11

This is a typical issue with JRE configuration in the java web project. Right-click on your project select "Build Path" and "Configure Build path". In the "Libraries" tab double click on "JRE System Libraries" and select workspace Default workspace. If you do not have one installed, please install it and follow the above process.

3

Go to buildPath and in libraries double click on JRE System Libraries and select workspace Default workspace.

2

if your project is a maven project try mvn clean install command. It worked for me.

1

I was facing the same issue then I change changed my installed JRE and point to jdk and it worked for me.

Eclipse -> Windows -> Preferences -> Java -> Installed JRE -> Add new (gave the path of installed java jdk)

Sumit Rane
  • 691
  • 1
  • 8
  • 14
0

I had this problem in IntelliJ. I was using JDK version 1.8.0_333, but my Maven runner version was 11.0.1. When I changed that to 1.8.0_333, the errors went away.

The Maven Runner version can be set under Preferences->Build, Execution, Deployment->Build Tools->Maven->Runner.

I'm still mystified by the error, because that Maven runner works fine with all my other projects.

MiguelMunoz
  • 4,548
  • 3
  • 34
  • 51