Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating sdk got NoClassDefFoundError for zxing

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)`
like image 645
Kishore Avatar asked Mar 27 '12 12:03

Kishore


4 Answers

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)

like image 75
Till Avatar answered Nov 17 '22 22:11

Till


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

like image 11
fly84021210 Avatar answered Nov 18 '22 00:11

fly84021210


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.

like image 1
Andy Smith Avatar answered Nov 17 '22 23:11

Andy Smith


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

like image 1
John O'Connor Avatar answered Nov 17 '22 22:11

John O'Connor