54

I have an Android project in eclipse IDE which was working. After some imports and tests, I get the error: java.lang.NoClassDefFoundError.

In my project I have two packages: the main one and the second one with some classes.

When I try to instantiate an object from the second package class in the main activity class, I am getting this error.

Here is the logcat:

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.neurospeech.wsclient.MDPIforEditorialBoard
at milos.mdpi.Journals.<init>(Journals.java:41)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1409)
at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1777)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4389)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)

Found the solution to my problem:

The solution can be found here: http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265

8 Answers8

55

Did you recently updated your eclipse android plugin (adt r17)? Then the following link might help:

How to fix the classdefnotfounderror with adt-17

Update: One year has passed since the question arose. I will keep the link, because even in 2013 it seem to help some people to solve the problem. But please take care what you are doing, see Erics comment below. Current ADT-Version is 22, I recommend using the most current version.

Minsky
  • 2,106
  • 28
  • 31
  • 1
    This worked for me also, but I had to temporarily switching the project target (from 2.2 -> 4.0.3 in my case) to get it to take effect. Possibly this was because my libs were already stored in a directory named "libs" – Stan Kurdziel Apr 09 '12 at 16:59
  • 2
    WARNING, That link says to get rid of everything in your Libraries tab, if you follow these directions and get rid of your "Android Dependencies" virtual folder, you will have to create a new project and reconstruct your program from scratch to get it back. – Eric Leschinski Sep 12 '13 at 21:48
  • @Chris Sim. Without knowing what your problem is exactly, I would say that the solution here is not for your problem. I guess you did clean and rebuild your projects and of course checked your libs are set correctly in the properties. – Minsky Oct 18 '13 at 10:52
  • when i did: right click on the project - properties - java build path - Order and export - tick Android private libraries and all the libraries that I added everything worked fine thanks – Chris Sim Oct 18 '13 at 12:09
26

Edit the build path in this order, this worked for me.

Make sure the /gen is before /src

enter image description here

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
ASP
  • 3,645
  • 1
  • 31
  • 45
  • Every time When I put /gen before /src, eclipse eats up the whole memory and freezes my computer – sma Oct 11 '13 at 20:41
17

I fixed the issue by just adding private libraries of the main project to export here:

Project Properties->Java Build Path->Order And Export

And make sure Android Private Libraries are checked.

Screenshot:

enter image description here

Make sure google-play-services_lib.jar and google-play-services.jar are checked. Clean the project and re-run and the classNotfound exception goes away.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
ernazm
  • 9,208
  • 4
  • 44
  • 51
  • that fixed it for me. Thanks. FYI, this happened after discarding changes made to the .classpath file of the project through GIT and selecting "Android Private Properties" again does actually add these two extra lines back to .classpath. – Erwan Oct 10 '13 at 02:37
1

Imaage

Go to Order and export from project properties and make sure you're including the required jars in the export, this did it for me

meowmeowbeans
  • 687
  • 7
  • 14
1

I've run into this problem a few times opening old projects that include other Android libraries. What works for me is to:

move Android to the top in the Order and Export tab and deselecting it.

Yes, this really makes the difference. Maybe it's time for me to ditch ADT for Android Studio!

multidynamic
  • 804
  • 8
  • 8
1

You can also get this error if you try to include a jar which was compiled with jdk 1.7 instead of 1.6.

In my case, I figured this out by trying to package my app with the Ant scripts provided by the SDK, instead of ADT, and I noticed these errors, which ADT did not show me:

  [dex] Pre-Dexing libjingle_peerconnection.jar -> libjingle_peerconnection-2f82c9bf868a6c58eaf2c3b2fe6a09f3.jar
   [dx]
   [dx] trouble processing:
   [dx] bad class file magic (cafebabe) or version (0033.0000)
   [dx] ...while parsing org/webrtc/StatsReport$Value.class
   [dx] ...while processing org/webrtc/StatsReport$Value.class

I recompiled my jar with jdk 1.6 and the error was fixed.

Val Blant
  • 1,664
  • 2
  • 24
  • 34
1

Try going to Project -> Properties -> Java Build Path -> Order & Export And Confirm Android Private Libraries are checked for your project and for all other library projects you are using in your Application.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

After Checking Java Build Path, Then add lines of code in manifest file.

<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
Fakhar
  • 3,946
  • 39
  • 35