使用Zxing库的Android二维码扫描变成崩溃

时间:2012-05-23 19:33:21

标签: android zxing qr-code scanning

我已将zxing库集成到我的应用程序中以扫描QR码。当我按下按钮并启动zxing扫描活动时,应用程序崩溃并在logcat上提供以下消息,

05-24 02:17:24.037: E/AndroidRuntime(516): FATAL EXCEPTION: main

05-24 02:17:24.037: E/AndroidRuntime(516): java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.code.looknmove/com.google.zxing.client.android.CaptureActivity}: android.content.res.Resources$NotFoundException: File res/xml/preferences.xml from 
drawable resource ID #0x7f050000

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.os.Handler.dispatchMessage(Handler.java:99)

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.os.Looper.loop(Looper.java:123)

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.app.ActivityThread.main(ActivityThread.java:4627)

05-24 02:17:24.037: E/AndroidRuntime(516):  at java.lang.reflect.Method.invokeNative(Native Method)

05-24 02:17:24.037: E/AndroidRuntime(516):  at java.lang.reflect.Method.invoke(Method.java:521)

05-24 02:17:24.037: E/AndroidRuntime(516):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

05-24 02:17:24.037: E/AndroidRuntime(516):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

05-24 02:17:24.037: E/AndroidRuntime(516):  at dalvik.system.NativeStart.main(Native Method)

05-24 02:17:24.037: E/AndroidRuntime(516): Caused by: android.content.res.Resources$NotFoundException: File res/xml/preferences.xml from drawable resource ID #0x7f050000

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.content.res.Resources.openRawResourceFd(Resources.java:860)

05-24 02:17:24.037: E/AndroidRuntime(516):  at com.google.zxing.client.android.BeepManager.buildMediaPlayer(BeepManager.java:97)

05-24 02:17:24.037: E/AndroidRuntime(516):  at com.google.zxing.client.android.BeepManager.updatePrefs(BeepManager.java:60)

05-24 02:17:24.037: E/AndroidRuntime(516):  at com.google.zxing.client.android.BeepManager.<init>(BeepManager.java:49)

05-24 02:17:24.037: E/AndroidRuntime(516):  at com.google.zxing.client.android.CaptureActivity.onCreate(CaptureActivity.java:165)

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

05-24 02:17:24.037: E/AndroidRuntime(516):  ... 11 more

05-24 02:17:24.037: E/AndroidRuntime(516): Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.content.res.AssetManager.openNonAssetFdNative(Native Method)

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.content.res.AssetManager.openNonAssetFd(AssetManager.java:426)

05-24 02:17:24.037: E/AndroidRuntime(516):  at android.content.res.Resources.openRawResourceFd(Resources.java:857)

05-24 02:17:24.037: E/AndroidRuntime(516):  ... 17 more

我无法发现实际问题是什么。因此,需要一些帮助来解决问题,以便发现它出了什么问题。

3 个答案:

答案 0 :(得分:3)

问题是您已将所有android/代码复制并粘贴到项目中,并且并不真正理解您复制的内容。以这种方式复制我们的应用强烈气馁。如果您是Android新手,那么尝试重用我们的代码可能太复杂了。

  1. android/core/
  2. 中删除您复制的所有代码
  3. 添加android-integration/
  4. 根据http://code.google.com/p/zxing/wiki/ScanningViaIntent
  5. 使用3行代码实施条形码扫描

答案 1 :(得分:1)

同样的问题,由此链接修复:

michalu zxing barcode

作为库,使用他的zxing库,您可以从页面底部的链接下载。它对我有用

答案 2 :(得分:0)

当我使用Zxing库并且通过这种技术解决它时,我遇到了同样的问题

在Manifest文件中提供Launcher活动的完整路径,例如“PacakageName.StartActivity”