{"record":{"id":"293c3c59719aeba2","repo":"YoKeyword/Fragmentation","slug":"can-t-find-container-please-call-loadrootfragment","errorCode":null,"errorMessage":"Can't find container, please call loadRootFragment() first!","messagePattern":"Can't find container, please call loadRootFragment\\(\\) first!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"fragmentation_core/src/main/java/me/yokeyword/fragmentation/TransactionDelegate.java","lineNumber":388,"sourceCode":"            if (transactionRecord.sharedElementList != null) {\n                sharedElementList = transactionRecord.sharedElementList;\n            }\n        }\n\n        if (handleLaunchMode(fm, from, to, toFragmentTag, launchMode)) return;\n\n        start(fm, from, to, toFragmentTag, dontAddToBackStack, sharedElementList, false, type);\n    }\n\n    private ISupportFragment getTopFragmentForStart(ISupportFragment from, FragmentManager fm) {\n        ISupportFragment top;\n        if (from == null) {\n            top = SupportHelper.getTopFragment(fm);\n        } else {\n            if (from.getSupportDelegate().mContainerId == 0) {\n                Fragment fromF = (Fragment) from;\n                if (fromF.getTag() != null && !fromF.getTag().startsWith(\"android:switcher:\")) {\n                    throw new IllegalStateException(\"Can't find container, please call loadRootFragment() first!\");\n                }\n            }\n            top = SupportHelper.getTopFragment(fm, from.getSupportDelegate().mContainerId);\n        }\n        return top;\n    }\n\n    private void start(FragmentManager fm, final ISupportFragment from, ISupportFragment to, String toFragmentTag,\n                       boolean dontAddToBackStack, ArrayList<TransactionRecord.SharedElement> sharedElementList, boolean allowRootFragmentAnim, int type) {\n        FragmentTransaction ft = fm.beginTransaction();\n        boolean addMode = (type == TYPE_ADD || type == TYPE_ADD_RESULT || type == TYPE_ADD_WITHOUT_HIDE || type == TYPE_ADD_RESULT_WITHOUT_HIDE);\n        Fragment fromF = (Fragment) from;\n        Fragment toF = (Fragment) to;\n        Bundle args = getArguments(toF);\n        args.putBoolean(FRAGMENTATION_ARG_REPLACE, !addMode);\n\n        if (sharedElementList == null) {\n            if (addMode) { // Replace mode forbidden animation, the replace animations exist overlapping Bug on support-v4.","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/YoKeyword/Fragmentation/blob/0394930a3e2368f210df31f2632fb89b9c44e121/fragmentation_core/src/main/java/me/yokeyword/fragmentation/TransactionDelegate.java#L370-L406","documentation":"getTopFragmentForStart determines which container a new fragment goes into based on the 'from' fragment's containerId. If the from fragment has mContainerId == 0 and was never added via a viewpager adapter (tag not starting with 'android:switcher:'), the library cannot locate a container and throws an IllegalStateException.","triggerScenarios":"Calling start()/startForResult() from a fragment that was never added through loadRootFragment or a viewpager, so its containerId is still 0 and its tag is a custom/unknown tag.","commonSituations":"Manually adding a SupportFragment with a plain FragmentTransaction then starting navigation from it; fragments created programmatically and added with custom tags; nested fragments not loaded via the library APIs.","solutions":["Load the fragment with loadRootFragment()/start() so the containerId is bound before navigating from it.","If the fragment is inside a viewpager, add it via the library's FragmentPagerAdapter so the 'android:switcher:' tag is set.","Ensure the from fragment was added to a container with a valid container id (bind via SupportFragmentDelegate.mContainerId)."],"exampleFix":"// before\ngetFragmentManager().beginTransaction().add(R.id.fl, myFragment, \"mine\").commit();\nmyFragment.start(new DetailFragment());\n// after\nloadRootFragment(R.id.fl, myFragment);\n// later\nmyFragment.start(new DetailFragment());","handlingStrategy":"validation","validationCode":"if (fromFragment.getSupportDelegate().mContainerId == 0 && (fromFragment.getTag() == null || !fromFragment.getTag().startsWith(\"android:switcher:\"))) {\n    // load via library APIs before starting navigation\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always add fragments via loadRootFragment()/start(), never raw FragmentTransaction.","Use the library's FragmentPagerAdapter for viewpager-hosted fragments.","Ensure every navigating fragment has a bound containerId."],"tags":["android","fragment","navigation","container"],"backgroundTag":"invalid-state-transition","analyzedSha":"0394930a3e2368f210df31f2632fb89b9c44e121","analyzedAt":"2026-09-10T13:16:30.469Z","contentChangedAt":"2026-09-10T13:16:30.469Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}