Crocodile
Crocodile

Reputation: 5845

I am getting a java.lang.NoClassDefFoundError when the class is clearly there

I am getting the following error when I am trying to use the library during runtime: java.lang.NoClassDefFoundError: com.google.api.client.extensions.android2.AndroidHttp I have added this library to my project, it is the first jar of the Maven dependencies( I am not 100% used to Maven though).

Also,My understanding is that Ant is looking for the jars in a libs folder, but Maven is using its own folder, and that works fine for an other project. So I am lost..any clues/help on how should I troubleshoot this would be much appreciated!

enter image description here

enter image description here

enter image description here

Upvotes: 2

Views: 2860

Answers (4)

yorkw
yorkw

Reputation: 41126

As a quick fix, By ticking Maven Dependencies in Java Build Path - Order and Export window should solve NoClassDefFoundError.

According to the screenshot you attached, it looks like you setup (or import) your Android project in Eclipse by the standard way google suggest in dev guide, but also somehow use Maven manage some of jar dependencies. This is not recommended, you should use either purely google standard way (libs/ folder since r17) or completely mavenize your android project for Dependency management.

Upvotes: 2

amp
amp

Reputation: 12352

Create a new folder called libs under your project folder and add this library to that folder.

I was having the same problem with kSOAP library and this solved my problem...

EDIT

I just saw that you already have that folder. Add the library...

Upvotes: 0

neevek
neevek

Reputation: 12128

Seems that the library is not exported.

Under your project folder, open the .classpath file, double check this line:

<classpathentry exported="true" kind="lib" path="google-http-client-android2-1.8.3-beta.jar"/>

If exported="false", change it to exported="true".

Upvotes: 0

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

Seems that you have not added the jar properly. Also seems that you have missed step 6 .

If you want to include this jar into your Android project, then you just do the following steps in your Eclipse environment.

  1. Right click on your project in the project's panel.
  2. Select “Properties” option.
  3. In the Properties window, Click on “Java Build Path”.
  4. In the right side of that window, select “Libraries” tab.
  5. Click on “Add External JARs” button and add this library where you have saved previously.
  6. Now click on “Order and Export” tab and check on “JarName.jar”
  7. Click on “Ok”.

Upvotes: 3

Related Questions