问题
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!



回答1:
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.
回答2:
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.
- Right click on your project in the project's panel.
- Select “Properties” option.
- In the Properties window, Click on “Java Build Path”.
- In the right side of that window, select “Libraries” tab.
- Click on “Add External JARs” button and add this library where you have saved previously.
- Now click on “Order and Export” tab and check on “JarName.jar”
- Click on “Ok”.
回答3:
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"
.
回答4:
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...
来源:https://stackoverflow.com/questions/10667048/i-am-getting-a-java-lang-noclassdeffounderror-when-the-class-is-clearly-there