1

When I run the app , It is force closed.How can QR code is scanning?I need to implement the bar-code scanner in my android application.Here I got the following error on my console.How can clear this error?...Here the zxing(code.jar) jar file is added also. I have used below code:

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

my console shows following error:

      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
user1575906
  • 65
  • 1
  • 11
  • include the zxing package in your build path - you are getting the error that zxing is not found -- import zxing as build from existing source and add to your project – Athul Harikumar Sep 11 '12 at 09:43
  • http://code.google.com/p/zxing/downloads/list – Athul Harikumar Sep 11 '12 at 10:00
  • please make sure that if you are using zxing as an external app to prompt the user to download the app if not available and if you want to integrate zxing into your app read http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/ – Athul Harikumar Sep 11 '12 at 10:01
  • http://stackoverflow.com/a/10346145/792232 check here – Abhi Sep 11 '12 at 10:04
  • thanks droidhot and Abhi it is uesful..i ll do this... – user1575906 Sep 11 '12 at 10:09
  • i have added the jar file..now also my app is force closed and also my console shows above error..read my update logout error on my question – user1575906 Sep 11 '12 at 10:27
  • This is nothing to do with including the zxing core or android code. You need android-integration. – Sean Owen Sep 11 '12 at 11:17

3 Answers3

0

Just install an app that can handle that intent (Zxing).

Also, catch that exception and prompt the user to install said application.

Charlie-Blake
  • 10,832
  • 13
  • 55
  • 90
0

At first glance, it looks like you haven't installed the ZXing Barcode Scanner app on your phone.

You can direct the user to the app in the market using a market link, like this: Install Application programmatically on Android

Community
  • 1
  • 1
seanhodges
  • 17,426
  • 15
  • 71
  • 93
0

Best solution by far is to use the IntentIntegrator provided by the project. It not only handles installing the app but other small gotchas.

http://code.google.com/p/zxing/source/browse/trunk#trunk%2Fandroid-integration

Sean Owen
  • 66,182
  • 23
  • 141
  • 173