我已成功让条形码扫描仪扫描并打开成功扫描的新意图。但是,当我尝试在扫描仪中单击后退按钮时出现此错误,而不是返回到我的应用程序时,问题是:
09-13 18:36:28.540 4227-4227/com.beerportfolio.beerportfoliopro E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=49374, result=0, data=null} to activity {com.beerportfolio.beerportfoliopro/com.example.beerportfoliopro.StatisticsPage}: java.lang.NullPointerException: println needs a message
at android.app.ActivityThread.deliverResults(ActivityThread.java:3660)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3710)
at android.app.ActivityThread.access$1100(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.d(Log.java:138)
at com.example.beerportfoliopro.ActionbarMenu.onActivityResult(ActionbarMenu.java:76)
at android.app.Activity.dispatchActivityResult(Activity.java:5275)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3656)
... 11 more
我用这个实现我的条形码扫描仪:
//get result value
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//retrieve scan result
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null) {
//we have a result
String scanContent = scanningResult.getContents();
Log.d("scan" , scanContent);
//launch async task for results
String url = "myurl";
new GetBeerDataFromUPCJSON(this).execute(url);
}
else{
Toast toast = Toast.makeText(getApplicationContext(),
"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
我刚刚尝试取出评论中提出的 Log.d,但出现此错误:
09-13 22:38:29.621 8588-8588/com.beerportfolio.beerportfoliopro E/WindowManager﹕ Activity com.example.beerportfoliopro.BeerPage has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@423db348 that was originally added here
android.view.WindowLeaked: Activity com.example.beerportfoliopro.BeerPage has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@423db348 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:468)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:419)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:351)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:171)
at android.view.Window$LocalWindowManager.addView(Window.java:558)
at android.app.Dialog.show(Dialog.java:282)
at com.example.beerportfoliopro.GetBeerRateJSON.onPreExecute(GetBeerRateJSON.java:52)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
at android.os.AsyncTask.execute(AsyncTask.java:534)
at com.example.beerportfoliopro.BeerPage.onCreate(BeerPage.java:100)
at android.app.Activity.performCreate(Activity.java:5066)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
09-13 22:38:29.912 8588-8588/com.beerportfolio.beerportfoliopro E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:784)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:476)
at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:182)
at android.app.Dialog.dismissDialog(Dialog.java:328)
at android.app.Dialog.dismiss(Dialog.java:311)
at com.example.beerportfoliopro.GetBeerRateJSON.onPostExecute(GetBeerRateJSON.java:74)
at com.example.beerportfoliopro.GetBeerRateJSON.onPostExecute(GetBeerRateJSON.java:27)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)