我有一個活動說A,啓動時需要額外資源。問題是什麼時候使用setDisplayHomeAsUpEnabled(true);我收到一個錯誤。這個錯誤顯然是由於沒有從B發送額外信息。如何使用後退按鈕,使用setDisplayHomeAsUpEnabled(true);我怎樣從B發送額外信息給A?當從操作欄中回撥按鈕時出現錯誤
活動A開始這樣說,從主要活動
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subscreen);
Bundle extras = getIntent().getExtras();
titleTask = extras.getString(DatabaseHelper.COLUMN_TITLE);
titleid = extras.getLong(DatabaseHelper.COLUMN_ROWID);
actionBar = getSupportActionBar();
actionBar.setTitle(titleTask);
actionBar.setDisplayHomeAsUpEnabled(true);
}
記錄錯誤時的B按下後退按鈕
04-26 12:39:54.355: E/AndroidRuntime(15573): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.group.RedPanda.FinalProject/com.group.RedPanda.FinalProject.SubScreen}: java.lang.NullPointerException
04-26 12:39:54.355: E/AndroidRuntime(15573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-26 12:39:54.355: E/AndroidRuntime(15573): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-26 12:39:54.355: E/AndroidRuntime(15573): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-26 12:39:54.355: E/AndroidRuntime(15573): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-26 12:39:54.355: E/AndroidRuntime(15573): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 12:39:54.355: E/AndroidRuntime(15573): at android.os.Looper.loop(Looper.java:123)
04-26 12:39:54.355: E/AndroidRuntime(15573): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-26 12:39:54.355: E/AndroidRuntime(15573): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 12:39:54.355: E/AndroidRuntime(15573): at java.lang.reflect.Method.invoke(Method.java:521)
04-26 12:39:54.355: E/AndroidRuntime(15573): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-26 12:39:54.355: E/AndroidRuntime(15573): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-26 12:39:54.355: E/AndroidRuntime(15573): at dalvik.system.NativeStart.main(Native Method)
04-26 12:39:54.355: E/AndroidRuntime(15573): Caused by: java.lang.NullPointerException
04-26 12:39:54.355: E/AndroidRuntime(15573): at com.group.RedPanda.FinalProject.SubScreen.onCreate(SubScreen.java:29)
04-26 12:39:54.355: E/AndroidRuntime(15573): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-26 12:39:54.355: E/AndroidRuntime(15573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
這聽起來並不像你想從B實際發送臨時演員到A.你只是試圖防止崩潰?在ActivityA的onResume()方法中,你很有可能得到'NullPointerException',所以你應該做一個空檢查,或者從onCreate方法中的「extras」中讀取。你可以發佈你的活動代碼嗎?以及LogCat異常? – tambykojak
好吧現在就做吧 – coderVishal
是的,我得到一個空指針異常 – coderVishal