views:

6551

answers:

4

I'm using Eclipse to learn to develop Android applications in Java. I haven't used Eclipse before.

The project I'm trying to use (supplied by OReilly as part of 'Android Application Development') is MJAndroid. When attempting to run the project, the Run fails, and the Problems tab mentions com.java.Object can't be found, and Eclipse asks me to check the build path. Clicking Properties -> Java Build Path -> Libraries, the message 'Unable to get system library for the project' is displayed.

On a working project, Properties -> Java Build Path -> Libraries has an entry for Android 1.1, which if I click Edit, has the classpath container path of com.android.ide.eclipse.adt.ANDROID_FRAMEWORK.

It seems a simple matter of adding the correct container path to my non-working project. However Eclipse seems determined to make this as difficult as possible. No matter what I chose to add - jars, externals jars, variables, libraries, class folders, external class folders, nothing seems to take the form of 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK' that the 'Android 1.1' entry on the working app has.

How can I add this namespace to my project so it resembles the working one?

I'm quite sure it's a problem with Eclipse's somewhat odd user interface. Frankly there' nothing I'd prefer more than a file to modify and set such information - my background is in Python, and the whole eclipse environment seems an unnecessary burden.

A: 

I would verify you have the correct version of Java installed as well as the Android SDK. I would recommend installing/reinstalling the ADT plugin in your eclipse, makes it alot easier to create the android project.

http://developer.android.com/sdk/1.5_r2/installing.html

willz
Since only one project is failing, and the other is working, I think my installation of ADT is working OK. I just need to get the failing project to also use the classpath container path of com.android.ide.eclipse.adt.ANDROID_FRAMEWORK per the working project.
nailer
+2  A: 

Sometimes Eclipse can get a bit funny (technical term) with classpath container resolution. You have a working project in your workspace, so you can rule out plugin installation issues. You could try opening the .classpath file (hidden by default, select the triangle in the top-right of the Package Explorer view, select Filters... and uncheck .* resources) and manually adding the container declaration.

`<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>`

You may then have to close the project and open it again (right-click->Close Project) before Eclipse recognises the change.

You may also find that there is an Android builder and/or nature. If you compare the .project files for the working and non-working versions you may see entries for Android builders/natures. Copying the relevant entries may resolve the issue.

Rich Seller
Thanks Rich, the missing entry in the hidden .classpath file was the problem. In addition, I also had to click Projects > Properties > Android and re-selecting Google APIs and Android 1.1.The project now has no more build issues. There's a few code issues however, but word round the net is that the sample app in O'Reilly's Android Book is fairly flaky.Thanks again Rich.
nailer
+6  A: 

I had faced the same issue when I imported a sample code downloaded from the internet. I am using android sdk 1.5 with 0.9 ADT plugins. Here is a simpler way to fix the andoid library reference issues

  • Right click on the project which has issues and select properties
  • Select the appropriate Android build (1.1, 1.5 or 1.5 with google api) and say ok
  • Again right click on the project and select "Android Tools > Fix Project Properties"
  • Fix the imports once (if required)
  • Refresh the project and you should be ready to go without any manual editing

Hope this helps.

Shreedhar

Shreedhar
A: 

Great tip. Reselecting the project build, the fix properties and the refresh did the trick. Thank you! Steph

Stephane Guerin
This is not an answer
mR_fr0g