執行代碼:錯誤:
java.lang.NullPointerException
11-15 09:04:21.023: E/AndroidRuntime(4057): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:591)
11-15 09:04:21.023: E/AndroidRuntime(4057): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416
if (mCurTransaction != null) { mCurTransaction.commitAllowingStateLoss();// if (manager != null)// manager.executePendingTransactions();緣由:當FragmentManager add,attach,remove,dettach時若是fragment爲null,如add(null)則容易mCurTransaction.commitAllowingStateLoss() 方法可能出現這個錯誤。解決方法:在執行這些方法時判斷fragment是否爲null。 如if(fragment != null) add(fragment);