Skip to content

Android Error – java.lang.NoClassDefFoundError for No Apparent Reason

Getting a java.lang.NoClassDefFoundError in Android for no apparent reason? Follow these two simple fixes in Eclipse to get your project working again.

Ramón Invarato

This error can show up unexpectedly -everything was working fine and suddenly you get this error- or after updating the ADT.

The following error appears in the Log, coming from one of the classes we created:

E/AndroidRuntime(5410): Caused by: java.lang.NoClassDefFoundError: miPropiaClaseDeEsteProyecto

 

It can also happen with an imported library, for example the "libGoogleAnalyticsV2.jar" library, showing:

E/AndroidRuntime(5410): Caused by: java.lang.NoClassDefFoundError: com.google.analytics.tracking.android.EasyTracker

Or, for example, with the "gcm.jar" library, showing:

E/AndroidRuntime(5410): Caused by: java.lang.NoClassDefFoundError: com.google.android.gcm.GCMRegistrar

 

Solution 1

We’ll try cleaning the project.

Note: We recommend making a backup copy of the project before continuing. Cleaning is usually safe, but sometimes it cleans more than it should.

To do so, go to the toolbar, click "Project" and, in the drop-down menu, choose "Clean…"

Cleaning an Android project in Eclipse 1 - www.jarroba.com

In the window that opens, select "Clean projects selected below" so you can pick the project you want to clean, select it and click "OK".

Cleaning an Android project in Eclipse 2 - www.jarroba.com

Check whether it works. If it still doesn’t, try solution 2.

 

Solution 2

First, check that the folder containing the jar files is named "libs".

 jar libraries in the libs folder in Android - www.jarroba.com

If it isn’t, you need to rename it (sometimes it’s called "lib" without the "s"; "lib" without the "s" is wrongly named, so rename it to "libs"). To rename the folder, right-click it, then choose "Refactor" and then "Rename…". In the pop-up window that opens, enter the name "libs" and confirm.

Renaming the libs folder - www.jarroba

Once that’s done, we continue. Right-click the project. Select "Build Path" and then "Configure Build Path…".

Eclipse Build Path for Android 1 - www.jarroba.com

Go to the "Order and Export" tab. You’ll most likely see that the ".jar" files are unchecked. Check all of them (you’ll probably have the one called "android-support-v4.jar"; in this example you can see two other libraries widely used in Android, "gcm.jar" and "libGoogleAnalyticsV2.jar", and you might have others). Click the "OK" button.

Eclipse Build Path for Android 2 - www.jarroba.com

Give it a try. If it still doesn’t work, clean the project one last time (do or redo solution 1 and test again). Everything should now be working correctly again.

“Android Error – java.lang.NoClassDefFoundError for No Apparent Reason” by Ramón Invarato at jarroba.com, licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0. Registered at Safe Creative.

Ramón Invarato

I design and build data platforms and intelligent systems, and I enjoy sharing that experience here.

You may also like

Android Error – Lost References

Getting errors across your whole Android project and "The type java.lang.String cannot be resolved"? Here's a quick fix using Organize Imports in Eclipse.

Dec 12, 2011

Comments

Leave a comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.