java.lang.Object cannot be resolved in Eclipse
Asked Answered
O

19

38

When I installed the latest installment in Mac OSX - the Mountain Lion - I experienced some problems getting Eclipse to work I also lost most of my Android developer files (but I still have my projects). I suspect this is due to the choice of removing the /Developer and move the XCode and other Apple developer tools (I placed my Android tools here).

I have now installed the latest version of Eclipse and the problem still seems to be around. There are errors in all my projects and I get an error message prompting:

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

I tried to check the Java class-path both in Eclipse and in my terminal and these seems to be OK. java and javac both run in my terminal and there is a valid path to the java source files in Eclipse (Under Preferences, Java, Installed JREs). That being said I'm not an expert in Eclipse so there may be that I have misunderstood how this problem ought to be solved. Anyone here with similar problems or who know the cure?

Oma answered 22/8, 2012 at 12:31 Comment(1)
This happens to me periodically, presumably because of an eclipse bug of some sort. The numerous answers below are all correct, but some are easier solutions to fixing the problem than others. First restart eclipse, clean all projects, double check your project has a link to the correct build path. If this fails, the method copied below by virtualdj of reordering the libraries in the JRE seems to be the easiest way to fool eclipse into reloading it.Nogging
C
42

Make sure that you have a valid JRE or JDK defined in the Java Build Path of your project. Right-click on your project, select Properties... and then Java Build Path.

Captive answered 22/8, 2012 at 12:33 Comment(8)
Thank you for the tip. Seems that they are 'Unable to get system library for the project' for one of the items listed. This is true for all the projects. Do you know if there is any good solution to fix this globally in Eclipse?Oma
You can define a Java runtime here: in the top menu select Window / Preferences... and then in the tree on the left Java / Installed JREs and then add one.Captive
The path points to: '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home' which seems to be a valid path and 1.6.0.jdk is also the only jdk under the JavaVirtualMachines folder.Oma
I just did this last night, I ran into the same issue, but I added the complexity of JDK 7 to the mix. @Dan is correct, you have to set your runtime preferences to the correct JRE. Once I did that, everything fell into place. The fact that the force you to download JRE 1.6 really screws you up. If you copied your workspace from somewhere else, you may have to delete the .classpath file under each project and rebuild it.Spital
I'm going to give you credit for your answer. After tinkering around with the build paths for both Android and Java I finally get some of the projects back on track :) Thank you.Oma
I've had this problem numerous times. The most recent just now, I fixed by going into the build path, "Order and Export", and bumping the gen folder up above the src folder. I have no idea how it could have gotten below, or how that could have caused this specific issue.Nogging
In build path, select "add library". Then choose "JRE System library" and select the appropriate JRE. Then, do a clean of your project and the error is away.Proa
This was the answer to my problem: #16731626Disgraceful
W
11

I had this problem moving a Maven project from Eclipse to RAD. I had a JSP file that worked in Tomcat and JBoss, but threw a NullPointerException in WebSphere on the form definition during the compile.

Anyway, after transforming the Maven project into an Ant project (mvn ant:ant), I imported the Ant project into RAD and got this error. The fix:

  1. Open the Java Build Path, selecting the Libraries tab.
  2. Find the JRE System Library and remove it.
  3. Add the JRE System Library.

Goofy, but it works. It must reset some property in a file. I don't know if the problem is the older version of Eclipse or RAD.

Wetmore answered 1/7, 2013 at 14:27 Comment(0)
T
5

After updating my Android SDK to make Appcelerator Titanium happy, I started getting "java.lang.Object cannot be resolved" for my Android projects in (non-Titanium) Eclipse.

I updated all dependencies in Eclipse, and the error healed after a restart of Eclipse.

Tumbleweed answered 28/2, 2013 at 15:25 Comment(0)
R
2

I had that error almost every time I launched Eclipse for the first time; if I close and then re-open Eclipse, the error is gone.

I found this solution useful, though (I've copied here to protect the link, credit goes to the original author):

  1. In Eclipse go to Windows -> Preferences -> Java -> Installed JREs.
  2. Select the currently active JRE/JDK and press the Edit button.
  3. Select the rt.jar and change its position in the list of JRE system libraries (e.g. press the Up button once).
  4. Confirm all changes, clean and rebuild the workspace.
  5. The next time you face the problem reposition the rt.jar again (or reset the order by pressing the Restore Default button).
Revkah answered 11/11, 2013 at 20:3 Comment(0)
A
1

please select your installed system jre version from java build path.

Afoul answered 7/1, 2013 at 13:35 Comment(0)
S
1

Try the following and problem will go away

  • 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.

Serai answered 24/1, 2014 at 15:26 Comment(1)
I had this issue with an apklib (ActionBarSherlock). I tried all the other solutions, but deleting and re-importing the project is the only thing that corrected it for me.Caroylncarp
H
1

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

Hudgins answered 15/6, 2015 at 12:53 Comment(0)
F
0

I got this error and what I had to do was remove the JRE from the Window/Preferences/Java/Installed JREs and re-add it. This somehow cleared up eclipse's cache and rebuilt the project successfully. To get rid of the error in the file-editor I also had to close it and open the file once again.

Fizgig answered 30/5, 2013 at 8:34 Comment(0)
S
0

My problem was that I had in Eclipse: Window / Preferences... and then in the tree on the left Java / Installed JREs: C:\Program Files\Java\jre7 I changed to: c:\Program Files (x86)\Java\jre7 It solved my problem.

Selfpossession answered 25/7, 2013 at 5:5 Comment(1)
You are now using the 32 bit version instead of the 64 bit.Fiedling
E
0

I had the same issue and none of the above solutions worked for me. Then I realized than the library (libs) folder was missing in the project. Once i added the libs folder and the corresponding Jar file, the issue was resolved..

Exorbitance answered 27/8, 2013 at 4:25 Comment(0)
P
0

If your project specific (or if not applicable, workspace default) JDK/JRE is being referenced correctly and you've just begun to get this issue out of the blue: restart Eclipse.

Unfortunately, "restart Eclipse" is one of the standard troubleshooting steps when a project won't build. Eclipse even has a dedicated entry under the File menu.

Pilsner answered 17/9, 2013 at 7:54 Comment(0)
C
0

I had to add the JDK under the build path. After adding the correct build path it worked.

Coiffeur answered 20/9, 2013 at 20:45 Comment(0)
T
0

I just had to restart eclipse, and the error went away. Strange.

Themis answered 26/10, 2013 at 21:29 Comment(1)
This worked for me. The error has occurred after I have updated SDK to 22.3 to include API 19.Clydesdale
R
0

I solved this by pointing my eclipse to the jre available in jdk.

Rigdon answered 25/2, 2014 at 3:34 Comment(0)
A
0

This error caused by invalid sdk is pointing in your project.properties file of your project. project.properties -> target=android-19 . change to version which is installed in your eclipse.The error will be gone.

Aubreyaubrie answered 29/4, 2014 at 11:22 Comment(0)
A
0

I had the same issue after moving from JRE7 to JDK7. Finally I had to remove the JRE7 configuration from the Eclipse preferences and then add the following two lines to the eclipse.ini file.

-vm C:\Program Files\Java\jdk1.7.0_55\bin\javaw.exe

Acima answered 14/5, 2014 at 8:35 Comment(0)
B
0

I had this problem, and I understood that Eclipse has automatically imported a core reference, instead of the reference for the project I needed.

Deleted the import, and rearranged it, and everything worked fine.

Bigham answered 15/5, 2014 at 8:3 Comment(0)
K
0

Same problem facing Me Project->properties->Android
And select the api level and also go in java build path and check some external jar file path if we already add in it.update the jar file path

Kiel answered 17/3, 2015 at 6:51 Comment(0)
G
0

On "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files": I found my project had 2 meta-inf.java files in 2 different directories with the same 'module ' on line one (a copy/paste error).
Once this was corrected, I cleared the meta-inf.java file with the issue, rebuilding it line by line, guided by Eclipse, until I had a working module configuration.

Graphology answered 3/12, 2022 at 6:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.