我使用此代碼重新加載我以前的活動,當我點擊後退按鈕但我的應用程序崩潰時。它得到空指針異常。什麼可能是這裏的問題?如何從其他活動重新加載活動
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
keyCode= KeyEvent.KEYCODE_BACK;
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent i=getIntent();
final Bundle b = i.getExtras();
Intent in = new Intent(this,UserProductActivity.class);
in.putExtra("id", Integer.parseInt(b.get("id").toString()));
in.putExtra("itemname", b.get("itemname").toString());
in.putExtra("amt", b.get("amt").toString());
in.putExtra("clientCode", b.get("code").toString());
in.putExtra("day", b.get("day").toString());
setResult(0,in);
return true;
}
return super.onKeyDown(keyCode, event);
}
logcat的
09-01 10:46:32.656: E/AndroidRuntime(4356): FATAL EXCEPTION: main
09-01 10:46:32.656: E/AndroidRuntime(4356): java.lang.NullPointerException
09-01 10:46:32.656: E/AndroidRuntime(4356): at com.example.senditem.UserItemDetailActivity.onKeyDown(UserItemDetailActivity.java:139)
09-01 10:46:32.656: E/AndroidRuntime(4356): at android.view.KeyEvent.dispatch(KeyEvent.java:2641)
09-01 10:46:32.656: E/AndroidRuntime(4356): at android.app.Activity.dispatchKeyEvent(Activity.java:2393)
09-01 10:46:32.656: E/AndroidRuntime(4356): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2023)
09-01 10:46:32.656: E/AndroidRuntime(4356): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:4118)
09-01 10:46:32.656: E/AndroidRuntime(4356): at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:4061)
09-01 10:46:32.656: E/AndroidRuntime(4356): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3144)
09-01 10:46:32.656: E/AndroidRuntime(4356): at android.os.Handler.dispatchMessage(Handler.java:107)
09-01 10:46:32.656: E/AndroidRuntime(4356): at android.os.Looper.loop(Looper.java:194)
09-01 10:46:32.656: E/AndroidRuntime(4356): at android.app.ActivityThread.main(ActivityThread.java:5400)
09-01 10:46:32.656: E/AndroidRuntime(4356): at java.lang.reflect.Method.invokeNative(Native Method)
09-01 10:46:32.656: E/AndroidRuntime(4356): at java.lang.reflect.Method.invoke(Method.java:525)
09-01 10:46:32.656: E/AndroidRuntime(4356): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:837)
09-01 10:46:32.656: E/AndroidRuntime(4356): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
09-01 10:46:32.656: E/AndroidRuntime(4356): at dalvik.system.NativeStart.main(Native Method)
在UserItemDetailActivity.java的第139行有什麼? – 2014-09-01 04:38:47
是否使用'startActivityForResult'? – 2014-09-01 04:39:48
是的我在之前的活動中使用startActivityForResult,因爲我傳遞的是我的意圖數據。我想要的是將我的數據從最後一個活動傳回到我以前的活動,這就是爲什麼我使用setResult – phoenix 2014-09-01 05:15:52