{"record":{"id":"25a2754968b842b5","repo":"YoKeyword/Fragmentation","slug":"not-attach","errorCode":null,"errorMessage":" not attach!","messagePattern":" not attach!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportFragmentDelegate.java","lineNumber":74,"sourceCode":"    boolean mAnimByActivity = true;\n    EnterAnimListener mEnterAnimListener;\n\n    private boolean mRootViewClickable;\n\n    public SupportFragmentDelegate(ISupportFragment support) {\n        if (!(support instanceof Fragment))\n            throw new RuntimeException(\"Must extends Fragment\");\n        this.mSupportF = support;\n        this.mFragment = (Fragment) support;\n    }\n\n    /**\n     * Perform some extra transactions.\n     * 额外的事务：自定义Tag，添加SharedElement动画，操作非回退栈Fragment\n     */\n    public ExtraTransaction extraTransaction() {\n        if (mTransactionDelegate == null)\n            throw new RuntimeException(mFragment.getClass().getSimpleName() + \" not attach!\");\n\n        return new ExtraTransaction.ExtraTransactionImpl<>((FragmentActivity) mSupport, mSupportF, mTransactionDelegate, false);\n    }\n\n    public void onAttach(Activity activity) {\n        if (activity instanceof ISupportActivity) {\n            this.mSupport = (ISupportActivity) activity;\n            this._mActivity = (FragmentActivity) activity;\n            mTransactionDelegate = mSupport.getSupportDelegate().getTransactionDelegate();\n        } else {\n            throw new RuntimeException(activity.getClass().getSimpleName() + \" must impl ISupportActivity!\");\n        }\n    }\n\n    public void onCreate(@Nullable Bundle savedInstanceState) {\n        getVisibleDelegate().onCreate(savedInstanceState);\n\n        Bundle bundle = mFragment.getArguments();","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/YoKeyword/Fragmentation/blob/0394930a3e2368f210df31f2632fb89b9c44e121/fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportFragmentDelegate.java#L56-L92","documentation":"extraTransaction() needs the TransactionDelegate which is only assigned in onAttach() when the host activity implements ISupportActivity. If called before the fragment is attached (mTransactionDelegate == null), a RuntimeException is thrown with the fragment's simple name prepended.","triggerScenarios":"Calling getSupportDelegate().extraTransaction() in the fragment's constructor, onCreateView(), or before onAttach completes; the host Activity does not implement ISupportActivity so mTransactionDelegate was never set.","commonSituations":"Loading fragments asynchronously and touching extraTransaction too early; performing transactions in onCreate before attach; host activity is a plain FragmentActivity.","solutions":["Call extraTransaction() only after the fragment is attached (e.g. in onActivityCreated(), onViewCreated(), or later lifecycle events).","Make sure the host activity extends SupportActivity / implements ISupportActivity so onAttach wires up the TransactionDelegate."],"exampleFix":"// before\n@Override\npublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {\n    extraTransaction().add(target, \"tag\").commit();\n// after\n@Override\npublic void onActivityCreated(@Nullable Bundle savedInstanceState) {\n    extraTransaction().add(target, \"tag\").commit();","handlingStrategy":"try-catch","validationCode":"if (isAdded()) { /* safe to call extraTransaction() */ }","typeGuard":null,"tryCatchPattern":"try {\n    getSupportDelegate().extraTransaction().add(to, tag).commit();\n} catch (RuntimeException e) {\n    // fragment not attached; defer to onActivityCreated\n}","preventionTips":["Only use extraTransaction() after onActivityCreated().","Host fragments in SupportActivity so the TransactionDelegate is wired in onAttach().","Avoid fragment work in constructors and onCreateView()."],"tags":["android","fragment","lifecycle"],"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"}