重启活动后的NPE

时间:2013-02-22 12:06:07

标签: java android android-activity

重新启动活动后:

Intent intent = getIntent();
finish();
startActivity(intent);

应用程序崩溃而没有任何对我的源代码的引用:

FATAL EXCEPTION: main
     java.lang.NullPointerException
     at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:980)
     at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:980)
     at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:980)
     at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:980)
     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1262)
     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2628)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:137)
     at android.app.ActivityThread.main(ActivityThread.java:4511)
     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:980)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
     at dalvik.system.NativeStart.main(Native Method)

在设备上只发生过几次。什么想法可能是错的?

1 个答案:

答案 0 :(得分:2)

为什么不使用Activity#recreate来完成这项工作?