{"record":{"id":"3e4038d48e345397","repo":"YoKeyword/Fragmentation","slug":"must-extends-fragment","errorCode":null,"errorMessage":"Must extends Fragment","messagePattern":"Must extends Fragment","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportFragmentDelegate.java","lineNumber":63,"sourceCode":"    private TransactionDelegate mTransactionDelegate;\n    TransactionRecord mTransactionRecord;\n    // SupportVisible\n    private VisibleDelegate mVisibleDelegate;\n    Bundle mNewBundle;\n    private Bundle mSaveInstanceState;\n\n    private ISupportFragment mSupportF;\n    private Fragment mFragment;\n    protected FragmentActivity _mActivity;\n    private ISupportActivity mSupport;\n    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;","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/YoKeyword/Fragmentation/blob/0394930a3e2368f210df31f2632fb89b9c44e121/fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportFragmentDelegate.java#L45-L81","documentation":"SupportFragmentDelegate wraps an ISupportFragment and requires it to be an android.support.v4.app.Fragment. The constructor throws immediately if the fragment instance is not a support-library Fragment, since all internal operations cast to and operate on Fragment.","triggerScenarios":"Creating a SupportFragmentDelegate (or extending SupportFragment's delegate setup) on a class extending android.app.Fragment, DialogFragment from the platform, or any non-Fragment class implementing ISupportFragment.","commonSituations":"Mixing platform android.app.Fragment with the support library; projects supporting very old Android versions still using native fragments; wrong import of Fragment.","solutions":["Make your fragment extend SupportFragment (me.yokeyword.fragmentation.SupportFragment).","Ensure your fragment extends android.support.v4.app.Fragment (support) or androidx.fragment.app.Fragment (AndroidX fork) and implements ISupportFragment.","Fix the Fragment import to the support/AndroidX package, not android.app.Fragment."],"exampleFix":"// before\nimport android.app.Fragment;\npublic class MyFragment extends Fragment {\n// after\nimport me.yokeyword.fragmentation.SupportFragment;\npublic class MyFragment extends SupportFragment {","handlingStrategy":"validation","validationCode":"if (!(f instanceof android.support.v4.app.Fragment)) {\n    throw new IllegalStateException(\"Fragment must extend support-library Fragment\");\n}","typeGuard":"boolean isSupportFragment(Object o) { return o instanceof android.support.v4.app.Fragment; }","tryCatchPattern":null,"preventionTips":["Extend SupportFragment instead of rolling your own ISupportFragment wrapper.","Watch imports: android.app.Fragment vs android.support.v4.app.Fragment.","Ban platform Fragment usage in the codebase via lint."],"tags":["android","fragment","wrong-base-class"],"backgroundTag":"invalid-constructor-argument","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"}