20

How to solve this NoClassDefFoundError. I have integrated Zxing in my app, every thing is working fine. Then I have updated my sdk and eclipse plugin, and when I run the project the log says

03-27 17:27:45.173: E/AndroidRuntime(8917): FATAL EXCEPTION: main
03-27 17:27:45.173: E/AndroidRuntime(8917): java.lang.ExceptionInInitializerError
03-27 17:27:45.173: E/AndroidRuntime(8917):     at java.lang.Class.newInstanceImpl(Native Method)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at java.lang.Class.newInstance(Class.java:1429)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.os.Looper.loop(Looper.java:123)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at java.lang.reflect.Method.invokeNative(Native Method)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at java.lang.reflect.Method.invoke(Method.java:521)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at dalvik.system.NativeStart.main(Native Method)
03-27 17:27:45.173: E/AndroidRuntime(8917): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
03-27 17:27:45.173: E/AndroidRuntime(8917):     at records.model.CaptureActivity.<clinit>(CaptureActivity.java:94)`
Kishore
  • 2,051
  • 5
  • 26
  • 45

10 Answers10

38

I didn't have to put the jar-library in assets or lib(s), but only tick the box for this jar in Properties -> Java Build Path -> "Order and Export" (it was listed before, but not selected)

You might have to do a project > clean after this to take effect! (Thanks mwengler and Mohamed)

Till - Appviewer.io
  • 4,529
  • 1
  • 31
  • 35
  • 1
    This worked for me once I did project > clean. If it works for you upvote so others in trouble find it. (And ideally @Kishore would accept this answer.) – mwengler Jul 28 '12 at 01:22
  • @mwengler Thanks for the clean tip, it only worked for me when I did the clean. @ Till Thanks for the helpful answer, would you please mention the "Clean" in the answer, because it only worked for me with the clean! – Mohamed A.Karim Oct 30 '12 at 18:44
  • I have met the same problem after upgrading Android SDK. And this method works. – flypen Jun 30 '13 at 05:05
11

Go to Properties -> Java Build Path -> "Order and Export"

Then order the core.jar to the first position and select it!

you must clean your project after your operation. Project -> clean

That will solve the problem

fly84021210
  • 131
  • 2
  • 10
  • 1
    Reordering to the top was not necessary for me. I've just needed to tick the check box. Ah, this has to be done for the zxing library and for your app. – Markus Rudel Aug 23 '12 at 07:41
1

This worked for me (after about 8 hours of messing around). The key is that you need to create the libs folder in the CaptureClient project, drop in core.jar, then add a reference to core.jar.

Then from your project, reference the CaptureClient project.

Wow, that was about a million times harder than it should have been!

https://stackoverflow.com/a/2248017/1173800

Community
  • 1
  • 1
jhilden
  • 12,207
  • 5
  • 53
  • 76
1

You are referencing the Class com.google.zxing.ResultMetadataType in CaptureActivity.java on line 94 but the definition for this Class cannot be found (ClassDefNotFound). If it cannot be found then it must not be on your class path.

There is probably a .jar file somewhere on your disk that contains com.google.zxing.ResultMetadataType (seemingly core.jar) place this on your project's class path to resolve this issue.

Andy Smith
  • 3,308
  • 4
  • 26
  • 34
1

For some reason, ADT is no longer including libraries from your build path in the generated .apk file.

To fix, create a "libs" folder in the root of your project (ie: bin, src, assets, libs) and put the core.jar file in there. Remove all other instances from your build path, and everything should work fine.

NoClassDefFoundError - Eclipse and Android

Community
  • 1
  • 1
John O'Connor
  • 5,244
  • 2
  • 24
  • 29
0

I had the same issue but was using the new Gradle build and Adroid Studio.

What solved it for me was to go outside of Android Studio and do a clean and build from the command-line using gradle:

gradle clean
gradle assembleDebug 

and the NoClassDefFound exception magically went away

Julian Cerruti
  • 1,918
  • 2
  • 16
  • 16
0

In my case the problem was with Android Build Tools I had version 18 but need to have Android Build Tools version 19 or later because I need to have my eclipse JDK compliance to 1.7 instead of 1.6 as CORE.JAR using Java version 1.7.

I would also suggest to look at the messages in android console during build process it will give you idea of exact problem.

Zain Ali
  • 15,535
  • 14
  • 95
  • 108
0

Add the core.jar to libs folder of your android project and don't add it as an external jar in java build path.

kunal
  • 1
  • 1
0

It means exactly what it says. You are using library code that you did not actually include into your app. Make sure the the contents of core.jar from the project are part of your project, as a library project.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
0

I had the same thing happen to me with a different .jar also after upgrading SDK and plugin.

Andrews answer below with link stackoverflow.com/a/2248017/180295 with points 3 and 4 worked for me.

Community
  • 1
  • 1
Cullan
  • 1,198
  • 10
  • 14