'boolean androidx.fragment.app.FragmentManagerImpl.isDestroyed()' 空对象引用
'boolean androidx.fragment.app.FragmentManagerImpl.isDestroyed()' on a null object reference
我收到此错误崩溃
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method boolean androidx.fragment.app.FragmentManagerImpl.isDestroyed()' on a null object reference
当 activity onStop() 和当我从 FragmentTransaction 中删除片段时
我添加了
@Override
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
我所有的片段,但没有帮助
我的代码
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
//t.replace(R.id.calendar1, weekendCaldroidFragment);
t.detach(weekendCaldroidFragment).add(R.id.calendar1, weekendCaldroidFragment).attach(weekendCaldroidFragment).commitNowAllowingStateLoss();
从 onDetach()
中删除所有这些代码 - 在任何最新版本的 Fragments 上都没有必要,这正是导致崩溃的原因。
我收到此错误崩溃
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method boolean androidx.fragment.app.FragmentManagerImpl.isDestroyed()' on a null object reference
当 activity onStop() 和当我从 FragmentTransaction 中删除片段时
我添加了
@Override
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
我所有的片段,但没有帮助
我的代码
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
//t.replace(R.id.calendar1, weekendCaldroidFragment);
t.detach(weekendCaldroidFragment).add(R.id.calendar1, weekendCaldroidFragment).attach(weekendCaldroidFragment).commitNowAllowingStateLoss();
从 onDetach()
中删除所有这些代码 - 在任何最新版本的 Fragments 上都没有必要,这正是导致崩溃的原因。