我在同一个容器中进行片段转换。但有时它会在片段提交时产生NullPointerException。下面是我的方法,它给出了一个错误。
public void goToMapFragment() {
if (getSupportFragmentManager().findFragmentByTag(Const.Tag.MAP_FRAGMENT) == null) {
MapFragment mapFragment = new MapFragment();
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
ft.setCustomAnimations(R.anim.fade_in_out,
R.anim.slide_out_left, R.anim.fade_in_out,
R.anim.slide_out_right);
ft.replace(R.id.contain_frame, mapFragment, Const.Tag.MAP_FRAGMENT);
//Here gives NullPointerException.....
ft.commitNowAllowingStateLoss();
}
}
请提供您的解决方案。
下面我附上它的堆栈跟踪。
java.lang.NullPointerException
at android.support.v4.app.FragmentManagerImpl.ensureExecReady(FragmentManager.java:1959)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1980)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
at com.gogo.MainDrawerActivity.goToMapFragment(MainDrawerActivity.java:392)