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
For me, the problem was that in the Project settings - Android tab, I had no Android version selected.
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.
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.
Unable to get system library for project
. I think this is the problem, but I don't know how to fix it.
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.
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.
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.
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
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
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!
Please see your .classpath file, and see if all reference lib projects or src projects are added with correct path and name.
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!
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.
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.
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.
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.
I right clicked project and Closed it. Then reopened it. That fixed the problem.
In my case, ADT needed update (in Eclipse menu Help/Check for Updates, or Help/Install New Software). Check your ADT!
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.
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.
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.
In my case, my project.properties had android-8 listed as the target, which I didn't have installed.
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.
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! ..
Try to create new project like this then try it
https://i.stack.imgur.com/2pnMa.jpg
Remove the folder libs in your project
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.
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
The way that helped me.
Take the following file from the working project: workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Working-project-name/.indexes Replace the broken project file: workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Broken-project-name/.indexes
Success story sharing