So i'm developing an app that can scan QR codes. I downloaded the ZXing library, built it using apache ant to get the core.jar, put it in my project folder and added it as a jar to the build path. No when i try do the following:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
I get the following error:
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>
Can anyone tell me how i set up the Zxing to use it properly or where i might be going wrong? Any help is greatly appreciated.
There are only three reasons you will ever get this error:
- The class genuinely doesn't exist. If you are using code from an official example and getting this, make sure you have the latest build of the library
- You have not added the jar to your build path. To fix this, right click on the jar in Eclipse, and do Build Path ► Add to Build Path.
- Your jar is not in the /libs folder. This happens when you have added the jar to the build path, but newer versions of ADT need it to be in /libs. Put it there and re-add it to the build path.
Do you have Zxing Barcode Scanner application installed? You have to install the application to scan using intent.
The CaptureActivity is not in the core.jar library. You have to include their Android project as library if you don't want to install and integrated in your own application. That's a lot of mess. Better install their application.
Another way is use Zbar library. I found this library easy to use and don't need their application installed. The only matter is if it support your desired barcode. I will recommend to check it out.
Edit:
Once I've tried to include zxing natively using this link.
Add ZXing barcode scanning natively in your Android project
ZXing QR Reader Direct Integration.
You can check this out.
来源:https://stackoverflow.com/questions/11959091/class-not-found-when-using-zxing