YoKeyword/Fragmentation · error · NullPointerException
There is no Fragment in the FragmentManager, maybe you need…
Error message
There is no Fragment in the FragmentManager, maybe you need to call loadRootFragment() first!
What it means
startWithPop() needs a current top fragment in the FragmentManager to determine the containerId for the mock pop. If getTopFragmentForStart returns null (no fragments managed yet), a NullPointerException is thrown advising to call loadRootFragment() first.
Solutions
- Call loadRootFragment(containerId, rootFragment) before using startWithPop().
- Use start(to) / loadRootFragment for the first fragment and reserve startWithPop for subsequent navigation.
- Guard navigation code to check SupportHelper.getTopFragment(fm) != null before calling startWithPop.
Example fix
// before supportFragment = new HomeFragment(); startWithPop(supportFragment, popTo); // after loadRootFragment(R.id.fl_container, new HomeFragment()); startWithPop(supportFragment, popTo);
Defensive patterns
Strategy: validation
Validate before calling
if (SupportHelper.getTopFragment(getSupportFragmentManager()) == null) {
loadRootFragment(R.id.fl_container, new HomeFragment());
return;
} Prevention
- Always call loadRootFragment() as the first navigation in an activity.
- Use startWithPop only for subsequent navigation.
- Rebuild the stack in onRestoreUserData/process-restore paths.
When it happens
Trigger: Calling startWithPop(to, popTo) when no fragment was previously loaded via loadRootFragment() into any container; empty FragmentManager at navigation time.
Common situations: First navigation of an app using startWithPop to replace a root; navigation code running before the activity's initial loadRootFragment call; restoring to a state where all fragments were popped.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- Can't find container, please call loadRootFragment() first!
- Must extends Fragment
- not attach!
- Fragment has not been attached to Activity!
- Must extends FragmentActivity/AppCompatActivity
AI-assisted analysis of YoKeyword/Fragmentation@0394930a3e (2026-09-10).
Data as JSON: /api/errors/079885359fe7e577.
Report an issue: GitHub.
Appendix: source
Thrown at fragmentation_core/src/main/java/me/yokeyword/fragmentation/TransactionDelegate.java:158
void showHideFragment(final FragmentManager fm, final ISupportFragment showFragment, final ISupportFragment hideFragment) {
enqueue(fm, new Action() {
@Override
public void run() {
doShowHideFragment(fm, showFragment, hideFragment);
}
});
}
/**
* Start the target Fragment and pop itself
*/
void startWithPop(final FragmentManager fm, final ISupportFragment from, final ISupportFragment to) {
enqueue(fm, new Action(Action.ACTION_POP_MOCK) {
@Override
public void run() {
ISupportFragment top = getTopFragmentForStart(from, fm);
if (top == null)
throw new NullPointerException("There is no Fragment in the FragmentManager, maybe you need to call loadRootFragment() first!");
int containerId = top.getSupportDelegate().mContainerId;
bindContainerId(containerId, to);
handleAfterSaveInStateTransactionException(fm, "popTo()");
FragmentationMagician.executePendingTransactionsAllowingStateLoss(fm);
top.getSupportDelegate().mLockAnim = true;
if (!FragmentationMagician.isStateSaved(fm)) {
mockStartWithPopAnim(SupportHelper.getTopFragment(fm), to, top.getSupportDelegate().mAnimHelper.popExitAnim);
}
removeTopFragment(fm);
FragmentationMagician.popBackStackAllowingStateLoss(fm);
FragmentationMagician.executePendingTransactionsAllowingStateLoss(fm);
}
});
dispatchStartTransaction(fm, from, to, 0, ISupportFragment.STANDARD, TransactionDelegate.TYPE_ADD);View on GitHub (pinned to 0394930a3e)