Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Approach for fixing NoClassDefFoundError? [duplicate]

Possible Duplicate:
NoClassDefFoundError - Eclipse and Android

I'm seeing this question is getting asked a lot in many different contexts. Perhaps we can set some strategies for locating and fixing it? I'm noobish myself so all I can contribute are horror stories and questions, sorry...

It seems this is thrown when a class is visible at compile time but not at run time... how can this happen?

In my case I am developing an app that uses the Google APIs, in Eclipse, for the Android platform. I've configured the Project Properties / Java Build Path / Libraries to include the gdata .jars and all is well. When I execute in the emulator I get a force close and the logcat shows a NoClassDefFoundError on a simple new ContactsService("myApp"); I've also tried a new CalendarService("myApp") with the same results.

Is it possible or desirable to statically bind at compile time to avoid the problem?

How could dynamic binding of an add-on library work in the mobile environment anyway? Either it has to be bound into my .apk or else I need to "install" it? ... hmmm.

Advice much appreciated.

like image 857
DJC Avatar asked Mar 16 '10 17:03

DJC


3 Answers

It seems this is thrown when a class is visible at compile time but not at run time... how can this happen?

The build classpath may include JARs that are not being packaged into the APK.

Is it possible or desirable to statically bind at compile time to avoid the problem?

It is possible, desirable, and necessary.

Outside of Eclipse, you just put the JARs you need in libs/ in your project, compile with Ant, and you are done.

Inside of Eclipse, one pattern I have had students use with success is to put the JARs you need in libs/ in your project, add them as JARs to the build path (note: not external JARs), and they get packaged as part of the APK. Note, though, that I do not personally use Eclipse, and so my experience with it is limited.

like image 61
CommonsWare Avatar answered Nov 20 '22 04:11

CommonsWare


For those having problem I was having the same error with my app. what I did to solve that was create a new project and copy my resource and source folders along with my manifest file into the new project (I deleted in advance those within the new project created) and voila.

like image 31
user1215183 Avatar answered Nov 20 '22 04:11

user1215183


When I got this, the problem was actually deeper in the queue; Dalvik converter had failed to convert some of the referenced libraries and still Eclipse allowed me to launch the project.

Check the Android SDK console to see if there are any errors reported.

like image 1
Zds Avatar answered Nov 20 '22 03:11

Zds