我有一个MainActivity
包含TabHost
其中一个选项卡的选项卡CardHolderActivity
,它还包含一个TabHost
带有两个选项卡的选项卡(它们Activities
也是)。一切都很好,直到我设置了最新的之一 -MyCardsActivity
我SaveOnInstanceState
将我的数据列表放在其中进行outState
捆绑。我正在启动很多其他应用程序,所以我的应用程序被杀死了。在我从最近打开的应用程序列表中再次启动它之后,我得到了一个NullPointerException
,这里是日志:
05-30 12:35:06.032: I/CrashLogger(28147): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.activities.MainActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.activities.CardsHolderActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.activities.MyCardsActivity}: java.lang.NullPointerException
05-30 12:35:06.032: I/CrashLogger(28147): --------- Stack trace ---------
05-30 12:35:06.032: I/CrashLogger(28147): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-30 12:35:06.032: I/CrashLogger(28147): android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-30 12:35:06.032: I/CrashLogger(28147): android.app.ActivityThread.access$600(ActivityThread.java:141)
05-30 12:35:06.032: I/CrashLogger(28147): android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-30 12:35:06.032: I/CrashLogger(28147): android.os.Handler.dispatchMessage(Handler.java:99)
05-30 12:35:06.032: I/CrashLogger(28147): android.os.Looper.loop(Looper.java:137)
05-30 12:35:06.032: I/CrashLogger(28147): android.app.ActivityThread.main(ActivityThread.java:5041)
05-30 12:35:06.032: I/CrashLogger(28147): java.lang.reflect.Method.invokeNative(Native Method)
05-30 12:35:06.032: I/CrashLogger(28147): java.lang.reflect.Method.invoke(Method.java:511)
05-30 12:35:06.032: I/CrashLogger(28147): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-30 12:35:06.032: I/CrashLogger(28147): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-30 12:35:06.032: I/CrashLogger(28147): dalvik.system.NativeStart.main(Native Method)
这是我得到这个之后的代码:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (cards != null)
outState.putSerializable(EXTRA_MY_CARDS, cards);
}
cards
是类型和类实现的static
变量。TreeSet<Card>
Card
Serializable
你们能告诉我为什么会这样吗?另外,我很惊讶在将应用程序恢复为终止状态后发生这种情况,根本没有任何问题onSaveInstanceState()
。而且我没有检索日期,也没有onRestoreInstanceState()
检索onCreate()
。