当我运行应用程序时,它被强制关闭。如何扫描二维码?我需要在我的 android 应用程序中实现条形码扫描仪。这里我的控制台上出现以下错误。如何清除此错误?.. .这里还添加了zxing(code.jar) jar 文件。我使用了以下代码:
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
HandleClick hc = new HandleClick();
findViewById(R.id.butQR).setOnClickListener(hc);
findViewById(R.id.butProd).setOnClickListener(hc);
findViewById(R.id.butOther).setOnClickListener(hc);
}
private class HandleClick implements OnClickListener{
public void onClick(View arg0) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
switch(arg0.getId()){
case R.id.butQR:
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
break;
case R.id.butProd:
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
break;
case R.id.butOther:
intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR");
break;
}
startActivityForResult(intent, 0); //Barcode Scanner to scan for us
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
TextView tvStatus=(TextView)findViewById(R.id.tvStatus);
TextView tvResult=(TextView)findViewById(R.id.tvResult);
if (resultCode == RESULT_OK) {
tvStatus.setText(intent.getStringExtra("SCAN_RESULT_FORMAT"));
tvResult.setText(intent.getStringExtra("SCAN_RESULT"));
} else if (resultCode == RESULT_CANCELED) {
tvStatus.setText("Press a button to start a scan.");
tvResult.setText("Scan cancelled.");
}
}
}
}
我的控制台显示以下错误:
09-06 00:56:36.198: D/AndroidRuntime(5417): Shutting down VM
09-06 00:56:36.198: W/dalvikvm(5417): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-06 00:56:36.208: E/AndroidRuntime(5417): FATAL EXCEPTION: main
09-06 00:56:36.208: E/AndroidRuntime(5417): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN (has extras) }
09-06 00:56:36.208: E/AndroidRuntime(5417): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
09-06 00:56:36.208: E/AndroidRuntime(5417): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
09-06 00:56:36.208: E/AndroidRuntime(5417): at android.app.Activity.startActivityForResult(Activity.java:2817)
09-06 00:56:36.208: E/AndroidRuntime(5417): at biz.tekeye.scanbarcode.Main$HandleClick.onClick(Main.java:33)
09-06 00:56:36.208: E/AndroidRuntime(5417): at android.view.View.performClick(View.java:2408)
09-06 00:56:36.208: E/AndroidRuntime(5417): at android.view.View$PerformClick.run(View.java:8816)
09-06 00:56:36.208: E/AndroidRuntime(5417): at android.os.Handler.handleCallback(Handler.java:587)
09-06 00:56:36.208: E/AndroidRuntime(5417): at android.os.Handler.dispatchMessage(Handler.java:92)
09-06 00:56:36.208: E/AndroidRuntime(5417): at android.os.Looper.loop(Looper.java:123)
09-06 00:56:36.208: E/AndroidRuntime(5417): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-06 00:56:36.208: E/AndroidRuntime(5417): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 00:56:36.208: E/AndroidRuntime(5417): at java.lang.reflect.Method.invoke(Method.java:521)
09-06 00:56:36.208: E/AndroidRuntime(5417): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-06 00:56:36.208: E/AndroidRuntime(5417): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-06 00:56:36.208: E/AndroidRuntime(5417): at dalvik.system.NativeStart.main(Native Method)
09-06 00:56:38.359: I/Process(5417): Sending signal. PID: 5417 SIG: 9