所以我正在开发一款可以扫描二维码的应用程序。我下载了ZXing库,使用apache ant构建它来获取core.jar,将它放在我的项目文件夹中,并将其作为jar添加到构建路径中。不,当我尝试执行以下操作时:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
我收到以下错误:
08-14 18:52:01.191: E/AndroidRuntime(617): FATAL EXCEPTION: main
08-14 18:52:01.191: E/AndroidRuntime(617): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.Wowser/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity in loader dalvik.system.PathClassLoader[/data/app/com.android.Wowser-1.apk]
08-14 18:52:01.191: E/AndroidRuntime(617): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
08-14 18:52:01.191: E/AndroidRuntime(617): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-14 18:52:01.191: E/AndroidRuntime(617): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-14 18:52:01.191: E/AndroidRuntime(617): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-14 18:52:01.191: E/AndroidRuntime(617): at android.os.Handler.dispatchMessage(Handler.java:99)
08-14 18:52:01.191: E/AndroidRuntime(617): at android.os.Looper.loop(Looper.java:123)
08-14 18:52:01.191: E/AndroidRuntime(617): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-14 18:52:01.191: E/AndroidRuntime(617): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 18:52:01.191: E/AndroidRuntime(617): at java.lang.reflect.Method.invoke(Method.java:507)
08-14 18:52:01.191: E/AndroidRuntime(617): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-14 18:52:01.191: E/AndroidRuntime(617): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-14 18:52:01.191: E/AndroidRuntime(617): at dalvik.system.NativeStart.main(Native Method)
08-14 18:52:01.191: E/AndroidRuntime(617): Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity in loader dalvik.system.PathClassLoader[/data/app/com.android.Wowser-1.apk]
08-14 18:52:01.191: E/AndroidRuntime(617): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-14 18:52:01.191: E/AndroidRuntime(617): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-14 18:52:01.191: E/AndroidRuntime(617): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-14 18:52:01.191: E/AndroidRuntime(617): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-14 18:52:01.191: E/AndroidRuntime(617): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
08-14 18:52:01.191: E/AndroidRuntime(617): ... 11 more
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.android.Wowser.DealsActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Register" />
<activity android:name=".SignIn" />
<activity android:name=".Options" />
<activity android:name=".Scan" />
</application>
有谁能告诉我如何设置Zxing正确使用它或我可能出错的地方?非常感谢任何帮助。
答案 0 :(得分:1)
您遇到此错误的原因只有三个:
答案 1 :(得分:0)
您是否安装了Zxing Barcode Scanner应用程序?您必须安装应用程序才能使用intent进行扫描。
CaptureActivity不在core.jar库中。如果您不想在自己的应用程序中安装和集成,则必须将其Android项目作为库包含在内。这太乱了。更好地安装他们的应用
另一种方法是使用Zbar库。我发现这个库易于使用,不需要安装它们的应用程序。唯一的问题是它是否支持您想要的条形码。我会建议你看一下。
修改强>
一旦我尝试使用此链接原生包含zxing。
Add ZXing barcode scanning natively in your Android project
ZXing QR Reader Direct Integration。
你可以看一下。