2

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.

Peter
  • 521
  • 2
  • 6
  • 20
  • Can you post your manifest file? – Cat Aug 14 '12 at 19:09
  • Do *not* copy and paste our manifest! – Sean Owen Aug 14 '12 at 19:34
  • @Sean Owen. Zxing is the best Barcode Scanner for android. But why there is no better way to integrate this without installing your app? You should create a library for android to easily handle this. – Shaiful Aug 14 '12 at 19:39
  • Hi @SeanOwen, i got the manifest entry from a tutorial, apologies. CAn you tell me the best way to integrate zxing? – Peter Aug 14 '12 at 19:40
  • @Peter. He will only tell you to use Intent. Because only then users have to install their app. – Shaiful Aug 14 '12 at 19:43
  • @Shaiful no, it's because people make apps that appear to be Barcode Scanner when it isn't. I get the bug reports. People that try to use Intents get their integration intercepted by his app because he copied . I tell people not to because this kind of UI copying is actually illegal -- not granted by the Apache license. OK by you now? – Sean Owen Aug 14 '12 at 19:59
  • @Sean Owen. OK. Now I understand. But few days ago I tried whatever way i can integrate zxing. Either way (with or without intent) it failed me. So I conclude with ZBar. Another word please. If you don't want your code being copied. Put them in your private repository. Your code will be safe. – Shaiful Aug 14 '12 at 20:15
  • @Shaiful Integrating by Intent is very easy, would have helped you on the mailing list if you had trouble. Do what works for you. To be clear: the authors' intent is to share and open source the code. I'm not going to hide it because some people use it improperly. Open source != do whatever you want with it. And I do not buy this "well you shouldn't have turned it loose!" argument, because almost all devs who use it are improving on it, contributing back, making good apps. It'd be a huge loss to not have that. It's why we opened it from Google in the first place. – Sean Owen Aug 14 '12 at 20:39
  • Yes. I know about the illegal thing. But It's still unacceptable from this famous scanner. – Shaiful Aug 14 '12 at 20:53
  • @SeanOwen I've went with using the library through Intent, the only reason i went otherwise was because I read online that's how people did it. I of course respect the work that ye have put into it and didnt intend on "copying/claiming" credit for it. Using intent is far easier yes i agree, and i'm sure when you were starting out mistakes were made too. All the same thanks for your response, it has been helpful. – Peter Aug 14 '12 at 20:57
  • 1
    @SeanOwen zxing is its excellent piece of work! Please publish a tutorial/guide on 'how to integrate it in app' (without installing the app). – iuq Dec 28 '13 at 17:31

1 Answers1

1

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.

Shaiful
  • 5,643
  • 5
  • 38
  • 41
  • I;m currently using the emulator for development, so how do i go bouts installing the Scanner application? Also does that mean the app won't run if someone doesnt have The Barcode scanner app on their phone? – Peter Aug 14 '12 at 19:27
  • I see in your manifest that you've used CaptureActivity. Did you include their Android project as library? Or Did you copy the CaptureActivity to your project? – Shaiful Aug 14 '12 at 19:30
  • Currently i did neiter, because i thought it was the only the core.jar file that was needed and i got the manifest entry from a tutorial which didnt mention adding the library.. How do i go about doing that? – Peter Aug 14 '12 at 19:37
  • 1
    Edited my answer. Follow the tutorials exactly. – Shaiful Aug 14 '12 at 19:44
  • You do not need any of these classes installed to integrate by Intent, which is the best way. The problem is, he's trying to embed the code, quite improperly, and doesn't know how to do it. – Sean Owen Aug 14 '12 at 19:57
  • Yes I don't need any of these class but your application from market. right? He's trying and he don't know, that's why he post his problem here. – Shaiful Aug 14 '12 at 20:26
  • Sean, I noticed that you answer a *lot* of these zxing questions. I presume you're a dev of the project? – Josh Barrow Mar 13 '14 at 18:19
  • @SeanOwen Needed to tag you so you'd be notified. Sorry about the dup. – Josh Barrow Mar 13 '14 at 18:20
  • @JoshBarrow yes I am the primary developer – Sean Owen Mar 14 '14 at 00:10