0

I am trying to integrate the QR reading capabilities of Zxing into a stand-alone app, and have been using this very helpful guide http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/ along with these pointers Integrating the ZXing library directly into my Android application but after having built the library, and followed all steps to launch this activity on a button press, it still does not work. The app launches, but upon pressing the button, it crashes.

activity_main.html

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="buttPress"
        android:text="@string/button_send"
        android:textColor="#FFFFFF"
        />

</RelativeLayout>

MainActivity.java

package se.mydomain.myapp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void buttPress(View view) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, 0);
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
           if (requestCode == 0) {
              if (resultCode == RESULT_OK) {
                 String contents = intent.getStringExtra("SCAN_RESULT");
                 String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
                 // Handle successful scan
              } else if (resultCode == RESULT_CANCELED) {
                 // Handle cancel
              }
           }
        }

}

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="se.mydomain.myapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.CAMERA"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="se.mydomain.myapp.MainActivity"
            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:screenOrientation="landscape"
   android:configChanges="orientation|keyboardHidden"
   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>
    </application>



</manifest>

This is the output in logcat upon launching and then pressing the button. Am I missing something obvious here? This happens both when emulating and when running on a phone, btw.

04-16 13:31:58.313: D/gralloc_goldfish(1359): Emulator without GPU emulation detected.
04-16 13:32:13.034: I/Choreographer(1359): Skipped 82 frames!  The application may be doing too much work on its main thread.
04-16 13:32:13.093: W/dalvikvm(1359): VFY: unable to resolve static field 872 (ISSUE_NUMBER) in Lcom/google/zxing/ResultMetadataType;
04-16 13:32:13.103: D/dalvikvm(1359): VFY: replacing opcode 0x62 at 0x0017
04-16 13:32:13.103: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.133: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/ResultPoint;)
04-16 13:32:13.133: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/ResultPoint;)
04-16 13:32:13.133: I/dalvikvm(1359): Could not find method com.google.zxing.ResultPoint.getX, referenced from method com.google.zxing.client.android.CaptureActivity.drawLine
04-16 13:32:13.143: W/dalvikvm(1359): VFY: unable to resolve virtual method 3648: Lcom/google/zxing/ResultPoint;.getX ()F
04-16 13:32:13.143: D/dalvikvm(1359): VFY: replacing opcode 0x6e at 0x0000
04-16 13:32:13.143: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.175: I/dalvikvm(1359): Could not find method com.google.zxing.Result.getResultPoints, referenced from method com.google.zxing.client.android.CaptureActivity.drawResultPoints
04-16 13:32:13.175: W/dalvikvm(1359): VFY: unable to resolve virtual method 3644: Lcom/google/zxing/Result;.getResultPoints ()[Lcom/google/zxing/ResultPoint;
04-16 13:32:13.183: D/dalvikvm(1359): VFY: replacing opcode 0x6e at 0x0003
04-16 13:32:13.183: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.224: I/dalvikvm(1359): Could not find method com.google.zxing.Result.toString, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecodeExternally
04-16 13:32:13.224: W/dalvikvm(1359): VFY: unable to resolve virtual method 3647: Lcom/google/zxing/Result;.toString ()Ljava/lang/String;
04-16 13:32:13.224: D/dalvikvm(1359): VFY: replacing opcode 0x74 at 0x007d
04-16 13:32:13.253: I/dalvikvm(1359): Could not find method com.google.zxing.Result.getText, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecodeExternally
04-16 13:32:13.253: W/dalvikvm(1359): VFY: unable to resolve virtual method 3645: Lcom/google/zxing/Result;.getText ()Ljava/lang/String;
04-16 13:32:13.264: D/dalvikvm(1359): VFY: replacing opcode 0x74 at 0x01c0
04-16 13:32:13.264: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.284: I/dalvikvm(1359): Could not find method com.google.zxing.Result.getBarcodeFormat, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecodeInternally
04-16 13:32:13.284: W/dalvikvm(1359): VFY: unable to resolve virtual method 3641: Lcom/google/zxing/Result;.getBarcodeFormat ()Lcom/google/zxing/BarcodeFormat;
04-16 13:32:13.284: D/dalvikvm(1359): VFY: replacing opcode 0x74 at 0x004c
04-16 13:32:13.324: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.354: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.364: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.384: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.384: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.394: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.394: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.414: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.454: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.454: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.484: I/dalvikvm(1359): Could not find method com.google.zxing.Result.getText, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecode
04-16 13:32:13.494: W/dalvikvm(1359): VFY: unable to resolve virtual method 3645: Lcom/google/zxing/Result;.getText ()Ljava/lang/String;
04-16 13:32:13.494: D/dalvikvm(1359): VFY: replacing opcode 0x6e at 0x0068
04-16 13:32:13.504: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.504: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.524: W/dalvikvm(1359): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
04-16 13:32:13.574: W/dalvikvm(1359): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/google/zxing/client/android/CaptureActivity;
04-16 13:32:13.584: W/dalvikvm(1359): Class init failed in newInstance call (Lcom/google/zxing/client/android/CaptureActivity;)
04-16 13:32:13.584: D/AndroidRuntime(1359): Shutting down VM
04-16 13:32:13.594: W/dalvikvm(1359): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-16 13:32:13.664: E/AndroidRuntime(1359): FATAL EXCEPTION: main
04-16 13:32:13.664: E/AndroidRuntime(1359): java.lang.ExceptionInInitializerError
04-16 13:32:13.664: E/AndroidRuntime(1359):     at java.lang.Class.newInstanceImpl(Native Method)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at java.lang.Class.newInstance(Class.java:1319)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at android.os.Looper.loop(Looper.java:137)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at java.lang.reflect.Method.invokeNative(Native Method)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at java.lang.reflect.Method.invoke(Method.java:511)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-16 13:32:13.664: E/AndroidRuntime(1359):     at dalvik.system.NativeStart.main(Native Method)
04-16 13:32:13.664: E/AndroidRuntime(1359): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
04-16 13:32:13.664: E/AndroidRuntime(1359):     at com.google.zxing.client.android.CaptureActivity.<clinit>(CaptureActivity.java:101)
04-16 13:32:13.664: E/AndroidRuntime(1359):     ... 15 more
04-16 13:32:19.034: I/Process(1359): Sending signal. PID: 1359 SIG: 9
Community
  • 1
  • 1
Christofer Ohlsson
  • 3,097
  • 4
  • 39
  • 56
  • 1
    This is the exact kind of headache you could avoid if you integrated via intents as the zxing authors intended ;-). Also if you insist upon copying their code into your project you should at least change the package name so that you are not using theirs. – FoamyGuy Apr 16 '13 at 13:39
  • 1
    I see people saying this all the time, but it's obviously easier to convince people to install one app than it is to have them install two. Regarding the package name, sure! I'm just trying to get this to work. – Christofer Ohlsson Apr 16 '13 at 13:41
  • @ChristoferOlsson understood but you're not permitted by the open source license to copy the UI. Also, it's poor form to interfere with our Intents by intercepting them via your copied manifest declarations. Being easier or more profitable for you doesn't obviate these factors. – Sean Owen Apr 16 '13 at 13:54
  • Sean: I do not want to do anything I'm not permitted to. I just want to get this running within an app of mine. As soon as that is done, I will start making sure I follow every rule and intention of your's. I am far, far from a finished state anyway. Is this approach okay? – Christofer Ohlsson Apr 16 '13 at 13:59
  • 1
    @ChristoferOlsson right but the exact portion of it that you are "just trying to get to work"(the CaptureActivity) you aren't permitted to use. If you want to re-use the scanning algorithms you have to create your own Activity(UI) So even if you get it to work it will be for naught because then you'll have to break it. `but it's obviously easier to convince people to install one app...` I don't think it is quite so cut and dry. Some people would rather leave the scanning to the Real BarcodeScanner because then it means your app doesn't need access to the (potentially unsafe) CAMERA permission. – FoamyGuy Apr 16 '13 at 14:06
  • I am definitely prepared to basically start over again once I get this to work. Because it will be so much easier for me to understand how it all works if I have a running code example that I myself have tampered with. Regarding the users... I don't think a great deal of average Joes carea bout the camera permission, no. If I knew that everybody had a scanner installed already, that'd be great. But I simply cannot build my project around having to convince people to install two apps. – Christofer Ohlsson Apr 16 '13 at 14:10
  • @ChristoferOlsson I have a similar problem, did you manage to fix it somehow? – Dom Oct 14 '14 at 12:59

0 Answers0