YoKeyword/Fragmentation · critical · RuntimeException

Must extends Fragment

Error message

Must extends Fragment

What it means

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.

Solutions

  1. Make your fragment extend SupportFragment (me.yokeyword.fragmentation.SupportFragment).
  2. Ensure your fragment extends android.support.v4.app.Fragment (support) or androidx.fragment.app.Fragment (AndroidX fork) and implements ISupportFragment.
  3. Fix the Fragment import to the support/AndroidX package, not android.app.Fragment.

Example fix

// before
import android.app.Fragment;
public class MyFragment extends Fragment {
// after
import me.yokeyword.fragmentation.SupportFragment;
public class MyFragment extends SupportFragment {
Defensive patterns

Strategy: validation

Validate before calling

if (!(f instanceof android.support.v4.app.Fragment)) {
    throw new IllegalStateException("Fragment must extend support-library Fragment");
}

Type guard

boolean isSupportFragment(Object o) { return o instanceof android.support.v4.app.Fragment; }

Prevention

When it happens

Trigger: 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.

Common situations: Mixing platform android.app.Fragment with the support library; projects supporting very old Android versions still using native fragments; wrong import of Fragment.

Related errors


AI-assisted analysis of YoKeyword/Fragmentation@0394930a3e (2026-09-10). Data as JSON: /api/errors/3e4038d48e345397. Report an issue: GitHub.

Appendix: source

Thrown at fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportFragmentDelegate.java:63

    private TransactionDelegate mTransactionDelegate;
    TransactionRecord mTransactionRecord;
    // SupportVisible
    private VisibleDelegate mVisibleDelegate;
    Bundle mNewBundle;
    private Bundle mSaveInstanceState;

    private ISupportFragment mSupportF;
    private Fragment mFragment;
    protected FragmentActivity _mActivity;
    private ISupportActivity mSupport;
    boolean mAnimByActivity = true;
    EnterAnimListener mEnterAnimListener;

    private boolean mRootViewClickable;

    public SupportFragmentDelegate(ISupportFragment support) {
        if (!(support instanceof Fragment))
            throw new RuntimeException("Must extends Fragment");
        this.mSupportF = support;
        this.mFragment = (Fragment) support;
    }

    /**
     * Perform some extra transactions.
     * 额外的事务:自定义Tag,添加SharedElement动画,操作非回退栈Fragment
     */
    public ExtraTransaction extraTransaction() {
        if (mTransactionDelegate == null)
            throw new RuntimeException(mFragment.getClass().getSimpleName() + " not attach!");

        return new ExtraTransaction.ExtraTransactionImpl<>((FragmentActivity) mSupport, mSupportF, mTransactionDelegate, false);
    }

    public void onAttach(Activity activity) {
        if (activity instanceof ISupportActivity) {
            this.mSupport = (ISupportActivity) activity;

View on GitHub (pinned to 0394930a3e)