我有一个使用Zxing进行QR码扫描的应用程序。以前它曾经很完美。但现在它已停止工作了。我没有更改代码或没有其他任何东西。我尝试过它,但没有找到任何解决方案。 还有其他人遇到过这样的问题,可以帮助我吗?
错误日志:
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
答案 0 :(得分:1)
我正在使用不同的库文件来扫描条形码和qrcode。它对我来说很好。
<强> 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);
}
}
对于,ScannerActivity
它提供了扫描代码的功能。
<强> 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;
}