2
如果用戶從我的應用程序(intent)啓動Zxing條形碼掃描器並按回按鈕,應該如何捕獲? - 它顯示「對不起MyApp被迫關閉」(或多或少,因爲我的語言不是英語)。 現在我有:Zxing處理後退按鈕
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
也許'intent'爲空。請發佈例外的日誌。 – yDelouis
據我所知,正確的數據是空的,但它應該反正'finish()'。 –
我想你想要檢索的數據在'scanResult'中,而不是'intent'。在'whatToDo(contents);'之前刪除兩行並添加'String contents = scanResult.getContents()'。我想你應該在調用'whatToDo'之前檢查'contents'是否爲null。 – yDelouis