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
- 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.
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
- 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.
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
- Must extends FragmentActivity/AppCompatActivity
- not attach!
- Fragment has not been attached to Activity!
- There is no Fragment in the FragmentManager, maybe you need…
- Can't find container, please call loadRootFragment() first!
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)