NullPointerException:对象空引用

时间:2018-06-01 11:07:52

标签: java android android-fragments nullpointerexception fragmentmanager

我正在替换片段,如果我替换片段,在替换之前我弹出堆栈回到之前的片段然后我再次点击替换片段我的应用程序被崩溃与此异常:

 NullPointerException: Attempt to invoke virtual method
 'java.lang.Object android.util.SparseArray.get(int)' on a null object reference

使用此日志:

  

java.lang.NullPointerException:尝试在空对象引用上调用虚方法'java.lang.Object android.util.SparseArray.get(int)'                                                          在android.support.v4.app.FragmentManagerImpl.getFragment(FragmentManager.java:902)                                                          在android.support.v4.app.FragmentStatePagerAdapter.restoreState(FragmentStatePagerAdapter.java:216)                                                          在android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1453)                                                          在android.view.View.dispatchRestoreInstanceState(View.java:13758)                                                          在android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2889)                                                          在android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2895)                                                          在android.view.View.restoreHierarchyState(View.java:13736)                                                          在android.support.v4.app.Fragment.restoreViewState(Fragment.java:510)                                                          在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1445)                                                          在android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)                                                          在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)                                                          在android.support.v4.app.FragmentManagerImpl.completeExecute(FragmentManager.java:2499)                                                          在android.support.v4.app.FragmentManagerImpl.access $ 600(FragmentManager.java:641)                                                          在android.support.v4.app.FragmentManagerImpl $ StartEnterTransitionListener.completeTransaction(FragmentManager.java:3851)                                                          在android.support.v4.app.FragmentManagerImpl.executePostponedTransaction(FragmentManager.java:2270)                                                          在android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2301)                                                          在android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)                                                          在android.support.v4.app.FragmentManagerImpl $ 1.run(FragmentManager.java:700)                                                          在android.os.Handler.handleCallback(Handler.java:739)                                                          在android.os.Handler.dispatchMessage(Handler.java:95)                                                          在android.os.Looper.loop(Looper.java:135)                                                          在android.app.ActivityThread.main(ActivityThread.java:5343)                                                          at java.lang.reflect.Method.invoke(Native Method)                                                          在java.lang.reflect.Method.invoke(Method.java:372)                                                          在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:905)                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

我该怎样防止这种情况? 感谢

0 个答案:

没有答案