我在Fragment
中有ViewPager
。
在Fragment的onCreate()中,我调用了下面的方法。
public void onCreate(Bundle savedInstanceState) {
...
this.group = groupManager.getGroup();
if (group == null) throw new NullPointerException("...");
...
}
如果group为null,则抛出NullPointerException。但是,没有发生此异常。而不是在onActivityCreated(),
public void onActivityCreated(Bundle savedInstanceState) {
...
group.getXX; // NullPointerException
...
}
有时会发生此异常,并非总是如此。我不知道为什么在onActivityCreated()中导致异常而不是onCreate()。
感谢您的回答。
group
是否会将片段拉回以替换为null?已添加:SourceFile:55是下面的group.getXX
行。
由java.lang.NullPointerException引起 xx.xxx.xxxFragment.onActivityCreated(SourceFile:55) android.support.v4.app.Fragment.performActivityCreated(SourceFile:1794) android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:967) android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1126) android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1108) android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:1917) android.support.v4.app.FragmentActivity.onStart(SourceFile:544) com.dunamu.stockplus.TrackingSherlockFragmentActivity.onStart(SourceFile:9) com.dunamu.stockplus.BaseActivity.onStart(SourceFile:123) android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171) android.app.Activity.performStart(Activity.java:5285) android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178) android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255) android.app.ActivityThread.access $ 800(ActivityThread.java:142) android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1203) android.os.Looper.loop(Looper.java:136) android.app.ActivityThread.main(ActivityThread.java:5118) java.lang.reflect.Method.invokeNative(Method.java) dalvik.system.NativeStart.main(NativeStart.java)