Tuesday, June 16, 2009

Eclipse build errors - java.lang.object cannot be resolved

Keywords:
eclipse 3.4.0 ganymede The type java.lang.object "cannot be resolved" "Cannot find the class file" "refers to the missing type"

Problem:
Opened eclipse, it needed to do a full workspace build (probably because ant scripts have updated class files and it needs to refresh). Random classes in the project now no longer compile. Examples of the errors being reported:



DescriptionResourcePathLocationType
The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class filesMyClass.javaMyProject/src/com/exampleline 1Java Problem
The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this projectMyProjectUnknownJava Problem
The method myMethod(SomeClass) from the type MyOtherClass refers to the missing type (insert java type here: InputStream|File|Vector|IOException|etc)MyOtherClass.javaMyProject/src/com/exampleline 123Java Problem


Solution:
It sounds like this has been a known issue (Bug 67414)that was resolved in 3.0 ... someone has commented that it's occurring for them in 3.4 as well.

In the mean time, the work around is to remove the JRE System Library from the project and then add it back again.
Here are the steps:
  1. Go to properties of project with the build error (right click > Properties)
  2. View the "Libraries" tab in the "Build Path" section
  3. Find the "JRE System Library" in the list (if this is missing then this error message is not an eclipse bug but a mis-configured project)
  4. Remove the "JRE System Library"
  5. Hit "Add Library ...", Select "JRE System Library" and add the appropriate JRE for the project (eg. 'Workspace default JRE')
  6. Hit "Finish" in the library selection and "OK" in the project properties and then wait for the re-build of the project
  7. Hopefully the error will be resolved ...

41 comments:

Anonymous said...

Thanks this solution worked!

I had this exact problem in a new install of Eclipse 3.5 (Galileo).

I followed the steps above and the problem went away.

This is what I think caused the problem in the first place: I installed Eclipse and Subclipse, checked out my project, and then set a new default JDK. I think the JRE System Library didn't pick up the new default JDK... maybe I should have set the new default JDK *before* checking out the project.

Anyway, all fixed, thanks!

Anonymous said...

The error may occur without changing the JDK.

I saw this problem when:
- opening Eclipse
- updating my local CVS repository

Basically, it occurs when a partial build is triggered but it is not systematic.

I managed to solve the problem by:
- changing the position of the JRE in the classpath (it is not necessary to remove it and add it again)
- changing the global JDK in order to trigger a clean rebuild. Any JDK is good enough. It has just to be different from the former one.

I have many projects in my workspace so it can be painful to change the classpaths one by one ;)

J. Le Cren

Anonymous said...

Great, this solution worked, had been a trouble for few days.

Huggie said...

Thanks a ton, this fixed up a problem I was having with all day!

Anonymous said...

Thank you so much.....
The solution is working....in my SAP Netweaver Developer Studio as well....

JaakkoS said...

Thanks, it worked!

Anonymous said...

the solution worked great thank you so much

shukaib1 said...

Thanks a lot for ur help. It really works.

Heba said...

WOW!!!! that worked like magic to me. thank u thank u thank u

Dason said...

I got 1 JRE1.6 running fine all the time but suddenly 1 day it has this same error. So, I tried this method and it didn't work. (but i believe it is correct working procedure)

So, I use my old JDK1.4 to run the program and it continue to works again. I believe it is the same error just that the JRE/JDK may corrupted. Download again and reinstall the JRE/JDK may helps.

Anonymous said...

thanks buddy, ur suggestion worked for me.

Shivram said...

yes, it worked.

Anonymous said...

Thanks this worked! The problem I was facing was the same but the reason was that I moved the project to another workspace manually and then opened eclipse. After adding the JRE library, works again.

limon said...

Thank you very much. I just fixed the problem.

Anonymous said...

Thanks alot for the guidance. The solution indeed work. I was struggling with it for last one day. Proved to be a great help.

Anonymous said...

Thanks solution works like a Charm ............

Anonymous said...

Excellent, thanks!

Anonymous said...

Thanks a lot

Sertaç DEMİR said...

Thank you it realy works for me :)

Anonymous said...

I just had the same problem in Eclipse Indigo. But the solution works. Great!

Anonymous said...

Thanks this worked for me too

Anonymous said...

Thanks this solution worked

Anonymous said...

Thank you very much. Just fixed the problem.

Anonymous said...

very helpful, thx!

Anonymous said...

Eclipse IDE for Java Developers
Version: Indigo Service Release 1
Build id: 20110916-0149

Reloaded project from disk, no changes made since last working online. TFS was unavailable, received a warning that the project is working offline. One class in the project failed to build with this error.

Libraries tab showed "Android Dependencies" and "Unable to get system library for project". Removed last entry, then added "JRE System Library" and "Android Classpath Container" to get it to work.

Anonymous said...

Thank you!

Prashant Ladha said...

Thank you. I am hoping to resolve some long pending issue on my office laptop tomorrow.

Nadeem Khan said...

Thanks very much dude, The solution worked for me.

Anonymous said...

I have been developing in this stable Indigo environment for a long time and just installed VeloEclipse plugin from Marketplace without any issue. On restart I got this error. Removing and readd JRE made it go away. Don't know what I would have done if I didn't find this post.

Anonymous said...

Thanks a ton. Worked like a charm.

Anonymous said...

Thanks for this resolving!!! It's worked today.

anand choubey said...

Thank You, the solution worked.

Stavan Mehta said...

Thanks. It works for me :)

Deepak Meena said...

Thanks for this easy and workfull answer. This solution worked for me!

Reza Moraveji said...

Worked for me as well. Thank you

I screwed up said...

I was stuck on it for hours... and this just solved it in a minute.. Can't thank you enough

Jono said...

worked for me too thanks for the input

nal said...

Thanks a lot.It works for me..:)

nal said...

Thanks for the solution..it works for me :)

Thin Ei Khaing said...

thz so much. It works great!!! :)

Chairinisa Napitupulu said...

Thank you!!!
This is work for me :")