我正在使用 Android 兼容性库,偶尔会感到奇怪NullPointerException
:
java.lang.NullPointerException
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:960)
at android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:768)
at android.support.v4.app.FragmentManagerImpl.startPendingDeferredFragments(FragmentManager.java:1104)
at android.support.v4.app.LoaderManagerImpl$LoaderInfo.onLoadComplete(LoaderManager.java:410)
at android.support.v4.content.Loader.deliverResult(Loader.java:103)
at android.support.v4.content.CursorLoader.deliverResult(CursorLoader.java:81)
at android.support.v4.content.CursorLoader.onStartLoading(CursorLoader.java:126)
at android.support.v4.content.Loader.startLoading(Loader.java:197)
at android.support.v4.app.LoaderManagerImpl$LoaderInfo.start(LoaderManager.java:262)
at android.support.v4.app.LoaderManagerImpl.doStart(LoaderManager.java:710)
at android.support.v4.app.Fragment.onStart(Fragment.java:981)
at android.support.v4.app.Fragment.performStart(Fragment.java:1332)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:906)
at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1240)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:612)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:431)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:139)
at android.support.v4.view.ViewPager.populate(ViewPager.java:804)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:433)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:405)
at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:386)
...
显然,我做错了什么,以允许FragmentManager
它进入这样的状态,它可能会像这样崩溃,但我不知道是什么。中的相关代码FragmentManagerImpl
没有为我提供任何线索。我猜mActivity
是null
在代码中的那个点?但这似乎是不可能的,因为活动已经在屏幕上,而且我没有向它添加任何片段 - 只是在ViewPager
.