因此,我正在开发一个可以扫描QR码的应用程序.我下载了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以正确使用它,或者我可能在哪里出错?任何帮助是极大的赞赏.
解决方法:
出现此错误只有三个原因:
>该类确实不存在.如果您使用的是官方示例中的代码并获取该代码,请确保您具有该库的最新版本
>您尚未将jar添加到构建路径.要解决此问题,请在Eclipse中的jar上单击鼠标右键,然后执行“构建路径”►“添加到构建路径”.
>您的jar不在/ libs文件夹中.当您将jar添加到构建路径中时,就会发生这种情况,但是较新版本的ADT需要将其放在/ libs中.将其放在此处并将其重新添加到构建路径.