NoClassDefFoundError when running app in emulator/phone
I'm using Eclipse to manage my Android project, which uses Amazon's Android libraries for AWS. I have added the library jar files to a ./libs folder, from which I added the libraries to my Java Build Path (Project properties -> Java Build Path -> Libraries -> Add JARS...). My app compiles correctly, but when I run it on an emulator or on a phone, I get a NoClassDefFoundError. I understand that this error is usually thrown when the application is compiled correctly but the libraries end up missing from the exported apk file.
Did I miss a step?
Edit:
Here's the s开发者_高级运维tack trace up to the point where my application references it.
java.lang.NoClassDefFoundError: org.apache.commons.httpclient.params.HttpClientParams
at com.amazonaws.http.HttpClient.configureHttpClient(Unknown Source)
at com.amazonaws.http.HttpClient.<init>(Unknown Source)
at com.amazonaws.AmazonWebServiceClient.<init>(Unknown Source)
at com.amazonaws.services.simpledb.AmazonSimpleDBClient.<init>(Unknown Source)
at com.amazonaws.services.simpledb.AmazonSimpleDBClient.<init>(Unknown Source)
at lee.medical.icu.dataentry.MainMenuActivity.connectToDb(MainMenuActivity.java:121)
Turns out, the jar files in the AWS SDK weren't properly built. It appears that they missed an old Apache library that is no longer publicly distributed. Amazon has updated the download, and the libraries no longer throw a NoClassDefFoundError.
Source: Forum post on AWS mobile dev forums
Do you see the libraries in the "Referenced libraries" point in the package view? If not, select the files in the project navigator, right click them "Build path" -> "add to buildpath"
I had the same problem, and I found the resolution in the post below. in short, you may want to place your external jar file in the libs directory (NOT in lib) then include it as an external jar file via right click on the project, then
properties >> java build path >> add external jars >> libs/yourLibrary.jar
the full explanation is here.
精彩评论