Java project in Eclipse: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
Asked Answered
G

28

261

I am getting the following error after importing a project in Eclipse:

The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

However, I have set the path as C:\Program Files\Java\jdk1.6.0_41 in Eclipse Kepler, through Window » Preferences » Java » Installed JREs.

Grunt answered 6/8, 2013 at 8:36 Comment(3)
i made "copy project" and error disappearedMccourt
The behaviour still occurs in Luna Service Release 2 (4.4.2). The solution here can still resolve the problem.Yuu
Reload the editor/project, and boom, it's fixed (solved when using vscode with springboot project).Abhorrence
R
286

This is an annoying Eclipse Bug which seems to bite now and then. See http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html for a possible solution, otherwise try the following;

  • Close the project and reopen it.

  • Clean the project (It will rebuild the buildpath hence reconfiguring with the JDK libraries)

    OR

  • Delete and Re-import the project and if necessary do the above steps again.

The better cure is to try NetBeans instead of Eclipse :-)

Ritual answered 6/8, 2013 at 8:57 Comment(13)
Same here. Bizarre Eclipse bug. The As the link says, removing the JRE library from project's classpath and re-add it fix the problem.Palliasse
Oh for a world that didn't have contracts with IBM.Co
I had that error on an Android project, for me clicking on Android Tools -> Fix Project Properties fixed it.Planospore
@Co why do we need contract with IBM. I am still not able to resolve this with IBM Java.Holm
I wonder if this is related to when you change the JAVA_HOME environment variable? I had changed my JAVA_HOME variable and this popped up. I just removed/readded the JRE library.Magnetize
Intellij instead of net beans or EclipseAspasia
We should be able to add a comment that all those people can vote for where NONE of the solutions worked. Otherwise the comments for this non-IDE are misleading.Glaring
Glad this bug still exists in Neon 3... rolleyesArchimedes
@Archimedes well, since a solution as simple as close + reopen works, it's probably not that much of a pressing issue from the dev's view, especially if the source of the bug is tricky to find.Wards
In my case the bug happens because the project was originally from another persons Eclipse... as the first comment mentions, rechoosing the JDK in ProjectProperties/Java Build Path fixes it.Leper
I'm getting this in VS Code.Harhay
Might help others: Check out the first answer in this link: #63447425Sita
Removing JRE did not work for me. Closing eclipse, reopening, cleaning the project and rebuilding worked for me.Drunk
S
278

The following steps could help:

  1. Right-click on project » Properties » Java Build Path
  2. Select Libraries tab
  3. Find the JRE System Library and remove it
  4. Click Add Library... button at right side » Add the JRE System Library (Workspace default JRE)
Selfinduction answered 11/2, 2014 at 6:12 Comment(4)
In my case it occurred because i have accidentally removed the JRE while importing the project [my fault]. This gave me a clue to fix the issue.Haeckel
in my case it wasn't exist at all, so I added it.Emerson
Although this worked in my case, solved 8 errors but gave me another 33!Plowboy
I am facing this issue in Android studio, any solution for this ?Preoccupation
B
15

This happened to me when I imported a Java 1.8 project from Eclipse Luna into Eclipse Kepler.

  1. Right click on project > Build path > configure build path...
  2. Select the Libraries tab, you should see the Java 1.8 jre with an error
  3. Select the java 1.8 jre and click the Remove button
  4. Add Library... > JRE System Library > Next > workspace default > Finish
  5. Click OK to close the properties window
  6. Go to the project menu > Clean... > OK

Et voilà, that worked for me.

Brighten answered 30/9, 2014 at 11:2 Comment(0)
G
14

Here is how I solved it: In Java-ADT: Windows - Preference - Java - Installed JREs Just add another JRE, pointing to the 'jre' folder under your JDK folder. (jre is included in the jdk). Make sure you chose the new jre.

Guillot answered 28/8, 2013 at 17:40 Comment(0)
S
9

Have you installed a different version JRE after , while using previous version of JRE in Eclipse .

if Not than :

  1. Right click on your project -> Build Path -> Configure Build Path
  2. Go to 'Libraries' tab
  3. Add Library -> JRE System Library -> Next -> Workspace default JRE (or you can Choose Alternate JRE form your System) -> Finish

if Yes than .

  1. Right click on your project -> Build Path -> Configure Build Path
  2. Go to 'Libraries' tab
  3. Remove Previous Version
  4. Add Library -> JRE System Library -> Next -> Workspace default JRE (or you can Choose Alternate JRE from your System) -> Finish
Sclerotomy answered 29/12, 2016 at 9:34 Comment(0)
T
8

Object class is the base class for all the classes in java, if you are missing this it means you don't have the jdk libs in your buildpath. I don't know much about Kepler but you need to make sure it points to a correct jdk for compilation and a correct jre for running your java apps.

However I have set the path as C:\Program Files\Java\jdk1.6.0_41 from eclipse Kepler toolbar->windows->preferences->java->installed jre

You are trying to point jdk instead of jre in your preferences. toolbar->windows->preferences->java->installed jre should point to a jre and not jdk.

Tertial answered 6/8, 2013 at 8:41 Comment(1)
I have tried with that as well. But still in the same error state.Grunt
C
7

This seems to be an Eclipse bug, though restarting Eclipse worked great for me, hope this helps somebody else too.

Edit: the next time I had this problem the solution above did not work - the problem was that the imported project I had - had the wrong java runtime set - which was not present (I had java 8 in my JRE present, but the project imported was set to Java 11, so I had to change the project java version to 8. Alternative would be to add more JRE's in the Eclipse preferences - if the project really needs a newer JRE to work)

Carbrey answered 5/5, 2016 at 17:58 Comment(0)
D
7

No amount of cleaning, closing/reopening the project&IDE, removing/adding the JRE in build path worked for me.

The solution I found was to remove the project from Eclipse (not from disk), remove the project's Eclipse files from the disk, and import into Eclipse again. That worked.

It is even faster if you are using Maven:

  1. Close Eclipse (no need to remove the project)
  2. Run mvn clean eclipse:clean eclipse:eclipse
  3. Open Eclipse. Your project is still present and the problem should be gone.
Deland answered 27/10, 2016 at 4:2 Comment(0)
E
5

None of the other answers worked for me. But doing this did:

  1. Right click the project in the package explorer.
  2. Source > Clean up...
  3. Next > Finish

When I did this Eclipse added an import into one of my classes. I think this occurred because I saved my project with a missing import, probably rushing to get home after work.

Eskilstuna answered 30/1, 2014 at 15:27 Comment(2)
thanks ..its working..please explain me how it works ?Silvestro
@SinghArjun I'm not sure but I think this happens when the project is saved with a missing import.Eskilstuna
C
4

Right click on project -->Show in Navigator In navigator view you can see .classpath file, do delete this file and build the project. This worked for me. PS. If you have integrated you eclipse project with some version control like perfoce/svn , then unlinking the project before you delete the .classpath will be helpful.

Chickenlivered answered 8/2, 2015 at 19:38 Comment(0)
C
3

Another problem could be that the Android Project Build Target is not set.

  1. Right-click the project
  2. Choose Properties
  3. Click Android
  4. Tick the appropriate Project Build Target
  5. Apply | OK
Coper answered 30/8, 2014 at 22:40 Comment(0)
O
2

I was facing this issue with play-java application on eclipse after adding a controller, I removed and reinstalled JRE through build path and then removed and imported my project which solved this issue automatically. Thanks gyro.

Orfurd answered 1/12, 2014 at 14:6 Comment(1)
This is the same as Ripon Al Wasim's answer, right?Deland
B
2

What solved my problem was to

1) Install the jdk under directory with no spaces:

C:/Java

Instead of

C:/Program Files/Java

This is a known issue in Windows. I fixed JAVA_HOME as well

2) I java 7 and java 8 on my laptop. So I defined the jvm using eclipse.ini. This is not a mandatory step if you don't have -vm entry in your eclipse.ini. I updated:

C:/Java/jdk1.7.0_79/jre/bin/javaw.exe

Instead of:

C:/Java/jdk1.7.0_79/bin/javaw.exe

Good luck

Bases answered 15/6, 2016 at 11:12 Comment(0)
C
2

I had the similar problem. It was a maven project with the following snippet of pom.xml.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>9</release>
            </configuration>
        </plugin>
        </plugins>
    </build>

I had to change the following.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>11</release>
            </configuration>
        </plugin>
        </plugins>
    </build>

If you have already installed JDK 11 and working with java 9 or java 10 as maven compiler, eclipse can not detect. Hence change the release to 11 or the actual installed version of JDK.

Courtenay answered 10/2, 2021 at 13:18 Comment(0)
G
1

I had same problem in eclipse windows that I couldn't added dependant .class files from the JNI. In order resolve the same, I ported all the code to NetBeans IDE.

Can not add all the classes files from the JNI/JNA folder in Eclipse (JAVA, Windows 7)

Glomerulus answered 30/4, 2015 at 12:12 Comment(2)
Why is it down voted ? See I do tried all the possible solutions, still could not resolve the issue and then I ported code to NetBeans. I answered this because if anybody stuck up, in worst case, s(he) might get help.Glomerulus
You may be right but for me JNI/JNA worked fine (for eclipse - 4.9.0) after deleting existing library and setting up default jre library, close project, open project.Saunders
R
1

While we are working with tomcat 6 and jdk 1.8 versions, some of the features will not work and this error you are getting is one. you need to change the jdk version to stable version(preferable jdk 1.6 or jdk 1.8_65) in eclipse to resolve this error.

in eclipse step 1: properties -> java build path -> jre system library(remove) step 2: add -> jre system library -> alternate jre -> installed jre -> add -> Standard VM -> (in jre home, place jdk path) -> finish

now clean and check the project

Reichstag answered 23/5, 2017 at 4:7 Comment(0)
T
1

I got this error because I have installed "Eclipse IDE for Enterprise Java Developers", I uninstalled this and installed "Eclipse IDE for Java Developers". Problem solved for me.

Tachycardia answered 19/6, 2019 at 11:15 Comment(0)
A
1

It's working for me after unchecking 'User '--releae option' in eclipse Java-compiler

In eclipse step 1: properties -> java Complier -> uchecking 'User '--releae option' option -> finish

Java version 13.0.1 Eclipse version : Eclipse IDE for Enterprise Java Developers.

Accrue answered 22/12, 2019 at 5:20 Comment(1)
This solved it for me but could anyone help me understand why?Aramaic
E
1

However I have set the path as C:\Program Files\Java\jdk1.6.0_41 from eclipse Kepler toolbar->windows->preferences->java->installed jre

If you have already added JRE and still showing error. try follow

right click on your project

project->build path-> configure build path -> java build path -> libraries tab -> select JRE system library and click edit button -> If alternative JRE is selected choose workspace default JRE.

this is how my error gone.

Erleena answered 24/9, 2020 at 16:43 Comment(0)
M
0

Happend to me after I've installed some updates in eclipse but forgot to restart afterwards. So maybe restarting eclipse might help.

Mara answered 12/4, 2018 at 9:27 Comment(1)
I tried to do that, but I'm not allowed to write comments yet.Mara
A
0

However trivial this might be, check your Java installation. For me, rt.jar was missing.

I found this after fiddling for half a day with Eclipse settings and getting nowhere. Desperate, I finally decided to try compiling the project from the command line. I wasn't expecting to see anything wrong since I thought it's an Eclipse issue but to my astonishment I saw this:

Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object

I don't know what happened to my Java installation and where did rt.jar go. Anyway this comes as a reminder to go through the fail checklist and tick all the boxes no matter how unbelievable they are. It would have saved me a lot of time.

Asur answered 7/1, 2019 at 6:33 Comment(0)
W
0

Right click on project, select Maven -> Update project. That should solve the issue.

Waaf answered 20/1, 2020 at 10:9 Comment(1)
doing eclipse -> maven -> update should be one of the step while troubleshooting.Paramnesia
G
0

In my case it was a big modular project and the 'red X' was showing only in the parent project. I went to the parent project

Properties -> Built Path

a removed the JRE Library there, just that, no JRE Library on the parent project anymore.

Gravitt answered 21/2, 2020 at 11:3 Comment(0)
L
0

None of these solutions worked for me. In my case the problem was that I had some Java code producing .java files and I had accidentally created a file called Class.java (content doesn't seem to matter). Removing the file fixed the problem.

Leaky answered 4/5, 2020 at 5:31 Comment(0)
N
0

sometimes this error happened after updating JAVA. if so go to eclipse.ini file in the same folder where eclipse existed. then change the line under -vm keyward to the new path of jre/bin folder to get the path go to programfiles -> java -> jre latest version -> bin folder copy the path and replace in line under -vm keyword.

Nannette answered 21/7, 2021 at 3:15 Comment(0)
C
0

This error message occurs when a class/java-project is unable to resolve correct JDK libraries. Say, in my primary Project A, I was getting this error. This Project A had a maven dependency for a project B. Project B pointed to JDK-11. Project A pointed to JDK-9

Correction I did : Made Project also point to JDK-11. It resolved the issue for me

Cankered answered 29/1, 2022 at 10:53 Comment(0)
F
0

For Gradle users, use eclipse plugin. I'm not using eclipse directly but jdtls on Neovim. This solves the issue for me.

build.gradle

plugins {
    id 'java'
    id 'eclipse'
}

Then run

gradle cleanEclipse eclipse
Farandole answered 7/7, 2022 at 17:5 Comment(0)
N
0

If you are using VScode Try The following steps:

  1. click ctrl+shift+p or F1
  2. type: Java: Clean Java Language Server Workspace >> Enter
  3. at the buttom right coner click Reload and delete.
Nunley answered 14/3 at 7:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.