64

Today I upgraded to Android SDK 2.3 and I also upgraded the Eclipse Plugin Androi Developer Tools 8.0 (from 0.9.9). I also upgraded my Java Development Kit to 1.6_22.

Now in Eclipse I get many errors in all my Android projects.

The error messages are like:

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

How can I fix this so I can use my Android projects again?

In the Build Path for these projects, I don't have any references to an android.jar but a message:

Unable to get system library for project

26 Answers 26

69

For me, the problem was that in the Project settings - Android tab, I had no Android version selected.

4
  • 1
    For me too, but with the addition that selecting a version in the Androids simply unset itself after reopening the preferences. Jul 6, 2011 at 13:51
  • 2
    This is held under Project/Properties (not Settings) on my version of Eclipse. The solution (changing Android 4.3 Build Target from unchecked to checked) worked for me, but I don't understand how it became unchecked - the project worked fine earlier and seemed to stop working without any significant change.
    – Andrew
    Feb 25, 2014 at 21:32
  • I had a target selected, out of the three I'd installed, but selected a different one anyway, applied, then selected the original one and applied. then build. it fixed for me. just like Iker Martin's answer
    – n611x007
    Aug 14, 2014 at 13:35
  • Worked for me too on Android 6.0 Oct 6, 2015 at 15:18
41

That is rather difficult to answer, given the limited information you have supplied. Here are some suggestions:

  • Make sure that an appropriate android.jar is in your build path, since that is where java.lang.Object would come from.

  • Do a Project > Clean, to make sure you have 1.6 .class files, in case that is part of the problem.

  • Try creating a new project from scratch and see if that works.

10
  • The android.jar seems to be in my Build path. I have already tried with Clean but it doesn't help. I get the same errors when I create new projects.
    – Jonas
    Dec 7, 2010 at 8:52
  • If I look in the Properties for my project, under "Java Build Path" there is a message: Unable to get system library for project. I think this is the problem, but I don't know how to fix it.
    – Jonas
    Dec 7, 2010 at 9:12
  • 14
    @Jonas: Go into Window > Preferences > Android and make sure your SDK is still configured with the appropriate directory. Dec 7, 2010 at 12:04
  • 36
    @Jonas: You might get that if you have your project configured for some target that you no longer have on the system (e.g., you removed it as part of your round of upgrades). In the project properties dialog, go into the Android area and make sure you have a valid target checked. Dec 7, 2010 at 12:40
  • 4
    I had this same problem and I solved it with @CommonsWare comment (the 3rd one). Aug 10, 2011 at 17:47
27

I had this problem even though I had a valid target selected. I fixed it by changing to a different target, applying changes and then changing back. That seems to have sorted it.

1
  • Yes, this actually re-created the entry for (in my case) Android 2.2 in my Java Build Path, which had been replaced by "unable to get system library for the project" after I installed a number of items. Now everything works as before.
    – Carl
    Dec 19, 2012 at 0:20
21

Project->Properties->Android : Select another Android Target (in my case Android 4.0.3) -> Apply changes. THEN select again your default Android Target, and that is all.

Hope this help.

1
  • Thanks, it works. Somehow it lost the path to android.jar, just uncheck and check again , it will work
    – zungnv
    Mar 20, 2014 at 7:01
3

This problem was caused for my old projects on a new machine that did not have an older Android SDK installed.

To fix, simply go into project.properties and observe your old version number:

# Project target.
target=Google Inc.:Google APIs:3

Simply update the version number, like so:

# Project target.
target=Google Inc.:Google APIs:7

You will find that Eclipse then picks up the right SDK version and starts working.

1
  • Worked for me. The project was referencing SDK 9 (which wasn't installed). When I edited the android version in the UI, the checkboxes wouldn't stay checked. Editing project.properties fixed things and allowed me to select the correct SDK version. Dec 9, 2012 at 20:39
3

No need to create a new project from scratch. If "Fix Project Properties" or "Add Library > Android Classpath Container" does not work, "project.properties" file might be missing in the root of your project folder. Add that file and set the Android target in the Project properties, re-add the Android Library, Fix Project Properties again, Android System Library should now be included in your project. Rebuilt, and you are good to go!

From my personal experience. For self documenting as well, since this happens quite often on me:

Eclipse Helios SR2
Android SDK R.20
Android NDK R8b
OSX 10.7.4
2

In my case the issue was related with the missing library path from the properties>android>library.

I cleared and re-entered the library paths in project.properties file

2

Had EXACT issue as the original Question! Had not done anything but close my project/Eclipse and was startled by all the errors upon reopening.

In my case I only needed to do was change/switch workspaces. o_O When I reselected my original workspace I then found everything was resolved and working again!

1
  • I also just closed and then reopened the project then everything worked. Sep 24, 2015 at 20:45
1

Please see your .classpath file, and see if all reference lib projects or src projects are added with correct path and name.

1

tl;dr: also check for stale SDK paths in the "local.properties" file.

Here's how I fixed it: I went through the answer given by Richard Le Mesurier, and also checked the path to the Android SDK in Window > Preferences > Android as mentioned by CommonsWare (since I did indeed change the SDK directory a while ago), however it still couldn't find it.

Then I noticed that I had a file called "local.properties" which referenced the old location for "sdk.dir". I changed that to the new location to match what was in Window > Preferences > Android. Then deselected the build target in Project > Properties > Android, hit Apply, re-selected it, and hit OK and cleaned the project. That worked! Thanks all!

1
  • ticking in one of the boxes in <project> -> Properties -> Android -> Project Build Target did it. There was none selected. Strange. I've also copied android-support-v4.jar to a freshly-created <project's root>/libs folder - don't know if it has to do with anything because in itself it didn't help, but then the tick did.
    – n611x007
    Sep 16, 2013 at 7:03
1

i have also encoutered this and solve it by changing the android choice in project properties. My error is because the project can't find proper lib from the android SDK. Then fix the project using android fix tool in right click of project, clean it and then correct.

0
1

I had this problem come out of nowhere.

What worked for me was to right-click the project, select Android Tools, Add support Library..

It is the android.jar that is missing, and this restores it.

1

Another possible explanation is that Eclipse has forgotten its Android plugin. This can happen if you switch workspaces, as happened in my case. I tried to re-import an existing Android project, and it couldn't find the basic java system libraries, since it was pointing to the standard android jars. Reinstalling the android plugin (Help->Eclipse Marketplace, then search for "Android" and pick "Android Development Tools for Eclipse") fixes it.

1

I right clicked project and Closed it. Then reopened it. That fixed the problem.

1

In my case, ADT needed update (in Eclipse menu Help/Check for Updates, or Help/Install New Software). Check your ADT!

1

I tried several options mentioned here, but nothing worked. Then I rebooted my Ubuntu machine and started Eclipse again. Then everything was solved. Just reboot.

1

java.lang.Object cannot be resolved in Eclipse

This problems started to appear recently for me after I upgraded ADT. As suggested above, when I uncheck+Apply/check+Apply project build target it would help , but the problem would come back eventually. So instead I just added android.jar explicitly to the build. This is the entry in the .classpath file

    <classpathentry kind="lib" path="/Applications/adt-bundle-mac-x86_64/sdk/platforms/android-19/android.jar"/>

This is more of a workaround as I would have to change it every time I change the SDK version, but at least no need to play with properties to get it to build when I restart Eclipse.

0

Try cleaning your project, that might help.

On eclipse, click on the menu item above called "Project", then click on "Clean Build". On that screen, check the checkbox that says "Clean projects selected below", select the project(s) that's giving you problems, and click Ok.

It will rebuild your project and that usually helps with strange eclipse errors like this.

2
  • 1
    Update your ADT on eclipse, they just pushed a new version to deal with some bugs: twitter.com/#!/romainguy/status/12222143299330050
    – velazcod
    Dec 8, 2010 at 1:48
  • I actually fixed this problem as CommonsWare described. And now I upgraded to ADT 8.0.1 and got the same problems again, but his fix solved it again.
    – Jonas
    Dec 8, 2010 at 12:22
0

In my case, my project.properties had android-8 listed as the target, which I didn't have installed.

0

my case was not created the right AVD

after AVD created, go to project Property and find Android, select the right SDK version and then go to JAVA Build Path, delete the library (Unable to get system library for project) and add android library.

0

The best way here as I tried before, is to create a new project and choose :

create a project from an existing source and choose the location of the android project that you want to import, then next, you will see the build target of android like : 2.3.3 or 2.1 ..

Just choose one of them then finish!

You are done! ..

0

Try to create new project like this then try it

Screenshot of 'New Android Project' window

1
  • after that clean the project and then try to run it Nov 28, 2011 at 13:11
0

Remove the folder libs in your project

0

Had the same issue (red erros all over my java source files) Solution was simple:

  • step 1. In the manifest file raise the version to android:minSdkVersion="8" (I created a new empty project and looked in it's manifest file) (it was originally android:minSdkVersion="4" because i want to support older android versions.)
  • step 2. right click the project and select Build
  • step 3. just to be safe: On the menu: Project Clean and check my project
  • step 4: finally I changed back In the manifest file to android:minSdkVersion="4" and it had no errors.

Hope it works for you.

0

In my case, The JRE went missing (disapear from Eclipse option).

All I did to fix this is re-add the JRE under Windows -> Preferences -> Java -> Installed JREs.

mine was located at /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

0

The way that helped me.

  1. Take the following file from the working project: workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Working-project-name/.indexes

  2. Replace the broken project file: workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Broken-project-name/.indexes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.