1

我是一名学生,作为我在学校的 android 项目的一部分,我需要包含一个条形码应用程序。我已经清楚地遵循了

http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/

整合ZXing。我在 3 个类 CaptureActivityHandler、DecodeHandler 和 SearchBookContentsActivity 中遇到了错误,这些错误通过将 switch-case 语句更改为 if-else 来解决,如下所示:

if(message.what==R.id.decode){
        decode((byte[]) message.obj, message.arg1, message.arg2);
    }
    else if(message.what==R.id.quit){
        running = false;
        Looper.myLooper().quit();
    }

在我的应用程序中,按下按钮后,条形码扫描仪意图应该启动。但我只收到一条错误消息,说我的应用程序已停止。logcat 消息如下:

03-06 20:18:58.631: D/dalvikvm(13812): Late-enabling CheckJNI
03-06 20:18:58.691: I/dalvikvm(13812): Turning on JNI app bug workarounds for target SDK version 10...
03-06 20:18:59.771: D/dalvikvm(13812): GC_FOR_ALLOC freed 57K, 3% free 8839K/9091K, paused 58ms
03-06 20:19:00.441: I/dalvikvm-heap(13812): Grow heap (frag case) to 11.692MB for 3145744-byte allocation
03-06 20:19:00.801: D/dalvikvm(13812): GC_CONCURRENT freed 1K, 3% free 11910K/12231K, paused 326ms+1ms
03-06 20:19:01.881: D/TextLayoutCache(13812): Using debug level: 0 - Debug Enabled: 0
03-06 20:19:06.201: D/dalvikvm(13812): GC_CONCURRENT freed 3118K, 25% free 9768K/12999K, paused 17ms+40ms
03-06 20:19:06.301: D/dalvikvm(13812): GC_FOR_ALLOC freed 4K, 23% free 10123K/12999K, paused 91ms
03-06 20:19:06.521: D/dalvikvm(13812): GC_FOR_ALLOC freed <1K, 20% free 10486K/12999K, paused 79ms
03-06 20:19:15.621: W/dalvikvm(13812): VFY: unable to resolve static field 1373 (ISSUE_NUMBER) in Lcom/google/zxing/ResultMetadataType;
03-06 20:19:15.621: D/dalvikvm(13812): VFY: replacing opcode 0x62 at 0x0017
03-06 20:19:15.621: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.651: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/ResultPoint;)
03-06 20:19:15.651: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/ResultPoint;)
03-06 20:19:15.651: I/dalvikvm(13812): Could not find method com.google.zxing.ResultPoint.getX, referenced from method com.google.zxing.client.android.CaptureActivity.drawLine
03-06 20:19:15.651: W/dalvikvm(13812): VFY: unable to resolve virtual method 3917: Lcom/google/zxing/ResultPoint;.getX ()F
03-06 20:19:15.651: D/dalvikvm(13812): VFY: replacing opcode 0x6e at 0x0000
03-06 20:19:15.651: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.651: I/dalvikvm(13812): Could not find method com.google.zxing.Result.getResultPoints, referenced from method com.google.zxing.client.android.CaptureActivity.drawResultPoints
03-06 20:19:15.651: W/dalvikvm(13812): VFY: unable to resolve virtual method 3913: Lcom/google/zxing/Result;.getResultPoints ()[Lcom/google/zxing/ResultPoint;
03-06 20:19:15.651: D/dalvikvm(13812): VFY: replacing opcode 0x6e at 0x0003
03-06 20:19:15.661: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.671: I/dalvikvm(13812): Could not find method com.google.zxing.Result.toString, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecodeExternally
03-06 20:19:15.671: W/dalvikvm(13812): VFY: unable to resolve virtual method 3916: Lcom/google/zxing/Result;.toString ()Ljava/lang/String;
03-06 20:19:15.671: D/dalvikvm(13812): VFY: replacing opcode 0x74 at 0x0053
03-06 20:19:15.671: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.681: I/dalvikvm(13812): Could not find method com.google.zxing.Result.getBarcodeFormat, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecodeInternally
03-06 20:19:15.681: W/dalvikvm(13812): VFY: unable to resolve virtual method 3910: Lcom/google/zxing/Result;.getBarcodeFormat ()Lcom/google/zxing/BarcodeFormat;
03-06 20:19:15.681: D/dalvikvm(13812): VFY: replacing opcode 0x74 at 0x004a
03-06 20:19:15.681: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.691: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.691: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.701: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.701: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.701: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.701: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.701: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.701: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.711: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.721: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.721: W/dalvikvm(13812): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
03-06 20:19:15.751: W/dalvikvm(13812): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/google/zxing/client/android/CaptureActivity;
03-06 20:19:15.751: W/dalvikvm(13812): Class init failed in newInstance call (Lcom/google/zxing/client/android/CaptureActivity;)
03-06 20:19:15.751: D/AndroidRuntime(13812): Shutting down VM
03-06 20:19:15.751: W/dalvikvm(13812): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
03-06 20:19:15.751: E/AndroidRuntime(13812): FATAL EXCEPTION: main
03-06 20:19:15.751: E/AndroidRuntime(13812): java.lang.ExceptionInInitializerError
03-06 20:19:15.751: E/AndroidRuntime(13812):    at java.lang.Class.newInstanceImpl(Native Method)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at java.lang.Class.newInstance(Class.java:1319)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at android.os.Looper.loop(Looper.java:137)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at android.app.ActivityThread.main(ActivityThread.java:4441)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at java.lang.reflect.Method.invokeNative(Native Method)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at java.lang.reflect.Method.invoke(Method.java:511)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-06 20:19:15.751: E/AndroidRuntime(13812):    at dalvik.system.NativeStart.main(Native Method)
03-06 20:19:15.751: E/AndroidRuntime(13812): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
03-06 20:19:15.751: E/AndroidRuntime(13812):    at com.google.zxing.client.android.CaptureActivity.<clinit>(CaptureActivity.java:107)
03-06 20:19:15.751: E/AndroidRuntime(13812):    ... 15 more

有人能帮帮我吗?我在 StackOverflow 上浏览了许多帖子,但找不到答案。

4

2 回答 2

2

如果您真的想嵌入 zxing 而不是将其与意图集成,我建议使用您可以在此处找到的开箱即用库:https://github.com/kennydude/zxing-lib

正如 Mark 建议的那样,最常见的方法是与他们的应用程序集成。

于 2013-03-06T15:30:29.557 回答
1

您需要按照链接给出的步骤进行操作

http://www.androidaz.com/development/zxing-qr-reader-direct-integration

你可以从下载 core.jar

http://repo1.maven.org/maven2/com/google/zxing/core/2.2/

以上对我有用,如果您的程序仍然崩溃,只需将 core-2.2.jar 放入库中并清理您的项目

于 2013-09-28T11:21:36.017 回答