NoClassDefFoundError:zxing的com.google.zxing.ResultMetadataType

时间:2015-08-06 03:49:45

标签: android zxing noclassdeffounderror barcode-scanner

我正在开发一个应用程序,通过ZXing在Android上扫描条形码。 我遵循这个tutorial

但是当我运行我的应用程序时,NoClassDefFoundError得到了,应用程序就完成了。

08-06 10:42:43.401: E/AndroidRuntime(10391): FATAL EXCEPTION: main
08-06 10:42:43.401: E/AndroidRuntime(10391): Process: com.foxconn.cnsbg.it.barcodescanner, PID: 10391
08-06 10:42:43.401: E/AndroidRuntime(10391): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/zxing/ResultMetadataType;
08-06 10:42:43.401: E/AndroidRuntime(10391):    at com.google.zxing.client.android.CaptureActivity.<clinit>(CaptureActivity.java:93)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at java.lang.reflect.Constructor.newInstance(Native Method)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at java.lang.Class.newInstance(Class.java:1572)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at android.app.ActivityThread.access$800(ActivityThread.java:149)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at android.os.Handler.dispatchMessage(Handler.java:102)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at android.os.Looper.loop(Looper.java:211)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at android.app.ActivityThread.main(ActivityThread.java:5333)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at java.lang.reflect.Method.invoke(Native Method)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at java.lang.reflect.Method.invoke(Method.java:372)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
08-06 10:42:43.401: E/AndroidRuntime(10391): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.zxing.ResultMetadataType" on path: DexPathList[[zip file "/data/app/com.foxconn.cnsbg.it.barcodescanner-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
08-06 10:42:43.401: E/AndroidRuntime(10391):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-06 10:42:43.401: E/AndroidRuntime(10391):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
08-06 10:42:43.401: E/AndroidRuntime(10391):    ... 15 more
08-06 10:42:43.401: E/AndroidRuntime(10391):    Suppressed: java.lang.ClassNotFoundException: com.google.zxing.ResultMetadataType
08-06 10:42:43.401: E/AndroidRuntime(10391):        at java.lang.Class.classForName(Native Method)
08-06 10:42:43.401: E/AndroidRuntime(10391):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
08-06 10:42:43.401: E/AndroidRuntime(10391):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
08-06 10:42:43.401: E/AndroidRuntime(10391):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
08-06 10:42:43.401: E/AndroidRuntime(10391):        ... 16 more
08-06 10:42:43.401: E/AndroidRuntime(10391):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

我搜索了Google并在CaptureActivity项目中修复了我的构建路径,如: enter image description here

并将core-2.2.jar添加到CaptureActivity项目和我的项目的 libs 文件夹中。我该如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

看一下这篇文章: Updating sdk got NoClassDefFoundError for zxing

引用直至

“我没有把jar文件库放在资产或lib中,但只在”属性“ - >”Java构建路径“ - >”订单和导出“(它是”订单和导出“)中勾选此jar的框。之前列出但未选中)

您可能需要执行一个项目&gt;在此之后清理生效!“

这对我有用!

答案 1 :(得分:0)

当存在您的代码所依赖的类文件并且它在编译时出现但在运行时未找到时,会出现

NoClassDefFoundError

由于core-2.2.jar中的类是应用程序的基础,为了保持一致性,您希望将此依赖项添加到lib文件夹中,而不是在构建路径外部提供此依赖项。

同时检查构建时间和运行时classpath的差异。快速检查一下可以解决您的问题。