Gaurav
Gaurav

Reputation: 1710

QR Code not working in Android

I have an application which uses Zxing for QR code scanning. It used to work perfectly before. But now it has stopped working. I havent change the code or didnt anything else. I tried working on it but didnt find any solution. Has anybody else faced such issue and can help me out?

Error log:

03-31 10:43:43.545: E/AndroidRuntime(9986): FATAL EXCEPTION: main
03-31 10:43:43.545: E/AndroidRuntime(9986): java.lang.RuntimeException: Unable to resume activity {com.google.zxing.client.android.CaptureActivity}: java.lang.NullPointerException
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2124)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.os.Looper.loop(Looper.java:123)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.app.ActivityThread.main(ActivityThread.java:3691)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at java.lang.reflect.Method.invokeNative(Native Method)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at java.lang.reflect.Method.invoke(Method.java:507)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at dalvik.system.NativeStart.main(Native Method)
03-31 10:43:43.545: E/AndroidRuntime(9986): Caused by: java.lang.NullPointerException
03-31 10:43:43.545: E/AndroidRuntime(9986):     at com.google.zxing.client.android.CaptureActivity.resetStatusView(CaptureActivity.java:632)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at com.google.zxing.client.android.CaptureActivity.onResume(CaptureActivity.java:175)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.app.Activity.performResume(Activity.java:3858)
03-31 10:43:43.545: E/AndroidRuntime(9986):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2114)
03-31 10:43:43.545: E/AndroidRuntime(9986):     ... 12 more

Upvotes: 1

Views: 1791

Answers (1)

Praveenkumar
Praveenkumar

Reputation: 24476

I'm using a different library file for scanning a barcode and qrcode. It's working fine for me.

MainActivity

    Button button = (Button)findViewById(R.id.btn);
    button.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            Intent intent = new Intent(v.getContext(), com.biggu.scannerdemo.ScannerActivity.class);
            intent.putExtra(Intents.Preferences.ENABLE_BEEP, true);
            intent.putExtra(Intents.Preferences.ENABLE_VIBRATE, true);

            ((Activity)v.getContext()).startActivityForResult(intent, SCANNER_REQUEST_CODE);
        }
    });
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode == Activity.RESULT_OK && requestCode == SCANNER_REQUEST_CODE) {

        Bundle extras = data.getExtras();
        String result = extras.getString("SCAN_RESULT");
        TextView textView = (TextView)findViewById(R.id.txt);
        textView.setText(result);
    }
}

For, the ScannerActivity it provides the functionality for scanning the code.

ScannerActivity

public class ScannerActivity extends CaptureActivity {

@Override
public int get_R_id_preview_view() {

    return R.id.preview_view;
}

@Override
public int get_R_id_viewfinder_view() {

    return R.id.viewfinder_view;
}

@Override
public int get_R_layout_scanner() {

    return R.layout.scanner;
}

@Override
public int get_R_raw_beep() {

    return R.raw.beep;
}

Upvotes: 1

Related Questions