Approach to fix NoClassDefFoundError?

Possible duplicate:
NoClassDefFoundError - Eclipse and Android

I see that this question is often asked in many different contexts. Perhaps we can establish some strategies for finding and fixing them? I'm a nikobish myself, so all I can do is horror stories and questions, sorry ...

It seems to be thrown when the class is visible at compile time, but not at runtime ... how can this happen?

In my case, I am developing an application that uses the Google APIs in Eclipse for the Android platform. I configured Project Properties / Java Build Path / Libraries to include gdata.jars, and all is well. When I run in the emulator, I gain strength and logcat shows NoClassDefFoundError in a simple new ContactService ("myApp"); I also tried the new CalendarService ("myApp") with the same results.

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

How does dynamic linking of an additional library work in a mobile environment? Either it should be attached to my .apk, or do I need to "install" it? ... hmmm.

Council appreciated.

+7
java android noclassdeffounderror eclipse gdata-api
source share
4 answers

It seems to be thrown when the class is displayed at compile time, but not at runtime ... how can this happen?

The assembly class path may include JARs that are not packaged in the APK.

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

Perhaps desirable and necessary.

Outside of Eclipse, you simply put the JAR files in libs/ into your project, compile with Ant, and you're done.

Inside Eclipse, one example that I used for students with success is to put the JARs that you need in the libs/ in your project, add them as JARs to the build path (note: not external JARs), and they get packed as part of the APK . Please note, however, that I personally do not use Eclipse, so my experience with it is limited.

+9
source share

For those who had a problem, I had the same error with my application. what I did to solve this was creating a new project and copying my resources and source folders along with my manifest file to a new project (I deleted in advance those that were created in the new project) and voila.

+2
source share

When I got this, the problem was actually deeper in line; Dalvik Converter was unable to convert some of the referenced libraries, and yet Eclipse allowed me to run the project.

Check the Android SDK console to see if there are any error messages.

+1
source share

In my case, I use my own library (MyLib), shared between two applications. Appendix A was closed when I added a new class to the library.

When I opened Application A to work on it, Eclipse recognized a new class and I was able to reference it. However, at startup I received an error.

It turned out that the imported library folder in Appendix A (named something like MyLib_src) does not reflect the changes made to my library project (MyLib).

  • To solve this problem, I updated application A, the changes were reflected, and Android could build my project correctly.

I did not find a link to this version of the problem, so I thought that I would add it to this list.

+1
source share

All Articles