android - QR 码在 Android 中不起作用

标签 android qr-code zxing

我有一个使用 Zxing 进行二维码扫描的应用程序。它曾经完美地工作过。但现在它已经停止工作了。我没有更改代码或没有其他任何内容。我尝试处理它但没有找到任何解决方案。 有没有其他人遇到过这样的问题并且可以帮助我?

错误日志:

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

最佳答案

我正在使用不同的库文件来扫描条形码和二维码。它对我来说很好用。

主 Activity

    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);
    }
}

对于ScannerActivity,它提供了扫描代码的功能。

扫描仪 Activity

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;
}

关于android - QR 码在 Android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9953217/

相关文章:

android - 创建二维码并显示在 ImageView 中

java - 在二维码中嵌入 URL

android - 未知异常安卓

android - 如何禁用我的应用程序中的所有过度滚动效果?

iOS 生成的二维码在其他平台无法识别

c# - 使用 IKVM 在 C# 中进行 zxing

android - 在 adobe air 中使用 android Intent

android - 带有 WebView 的 ListView 作为标题自动滚动

android - 将 SQLite 列转换为行

qr-code - 在二维码中存储二进制数据