2

如果用户从我的应用程序(意图)启动 Zxing 条码扫描器然后按下返回按钮,我应该如何捕捉?- 它显示“抱歉 MyApp 被迫关闭”(或多或少因为我的语言不是英语)。我现在有:

if (scanResult != null) {
          intent.putExtra("com.tajchert.kolejrogowska.SCAN.SCAN_MODE", "QR_CODE_MODE");
          String contents = intent.getStringExtra("SCAN_RESULT");
          whatToDo(contents);
      }
      else{
          finish();
      }

没有else{}阻塞是一样的。

编辑:日志:

11-25 00:16:33.738: E/AndroidRuntime(21969): FATAL EXCEPTION: main
11-25 00:16:33.738: E/AndroidRuntime(21969): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=49374, result=0, data=null} to activity {com.tajchert.kolejrogowska/com.tajchert.kolejrogowska.Kody}: java.lang.NullPointerException
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread.access$2800(ActivityThread.java:125)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.os.Looper.loop(Looper.java:123)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread.main(ActivityThread.java:4627)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at java.lang.reflect.Method.invokeNative(Native Method)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at java.lang.reflect.Method.invoke(Method.java:521)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at dalvik.system.NativeStart.main(Native Method)
11-25 00:16:33.738: E/AndroidRuntime(21969): Caused by: java.lang.NullPointerException
11-25 00:16:33.738: E/AndroidRuntime(21969):    at com.tajchert.kolejrogowska.Kody.onActivityResult(Kody.java:77)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.Activity.dispatchActivityResult(Activity.java:3890)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
11-25 00:16:33.738: E/AndroidRuntime(21969):    ... 11 more
4

1 回答 1

4

输入这个:

if (scanResult != null) {
    String contents = scanResult.getContents();
    if(contents != null)
        whatToDo(contents);
    else
        finish();
}
于 2012-11-24T23:59:56.963 回答