YoKeyword/Fragmentation · error · RuntimeException
not attach!
Error message
not attach!
What it means
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.
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.
Example fix
// before
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
extraTransaction().add(target, "tag").commit();
// after
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
extraTransaction().add(target, "tag").commit(); Defensive patterns
Strategy: try-catch
Validate before calling
if (isAdded()) { /* safe to call extraTransaction() */ } Try / catch
try {
getSupportDelegate().extraTransaction().add(to, tag).commit();
} catch (RuntimeException e) {
// fragment not attached; defer to onActivityCreated
} Prevention
- Only use extraTransaction() after onActivityCreated().
- Host fragments in SupportActivity so the TransactionDelegate is wired in onAttach().
- Avoid fragment work in constructors and onCreateView().
When it happens
Trigger: 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.
Common situations: Loading fragments asynchronously and touching extraTransaction too early; performing transactions in onCreate before attach; host activity is a plain FragmentActivity.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Fragment has not been attached to Activity!
- Must extends Fragment
- There is no Fragment in the FragmentManager, maybe you need…
- Can't find container, please call loadRootFragment() first!
- Must extends FragmentActivity/AppCompatActivity
AI-assisted analysis of YoKeyword/Fragmentation@0394930a3e (2026-09-10).
Data as JSON: /api/errors/25a2754968b842b5.
Report an issue: GitHub.
Appendix: source
Thrown at fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportFragmentDelegate.java:74
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;
this._mActivity = (FragmentActivity) activity;
mTransactionDelegate = mSupport.getSupportDelegate().getTransactionDelegate();
} else {
throw new RuntimeException(activity.getClass().getSimpleName() + " must impl ISupportActivity!");
}
}
public void onCreate(@Nullable Bundle savedInstanceState) {
getVisibleDelegate().onCreate(savedInstanceState);
Bundle bundle = mFragment.getArguments();View on GitHub (pinned to 0394930a3e)