Tencent/QMUI_Android · error · RuntimeException
must call #configFragmentContainerView() in onCreateView()
Error message
must call #configFragmentContainerView() in onCreateView()
What it means
QMUINavFragment requires a FragmentContainerView child whose id was configured via configFragmentContainerView() during onCreateView. In onViewCreated it looks up the container by getContextViewId(); if findViewById returns null, the navigation container does not exist and a RuntimeException is thrown rather than failing later with a confusing NPE.
Source
Thrown at arch/src/main/java/com/qmuiteam/qmui/arch/QMUINavFragment.java:115
} catch (ClassNotFoundException e) {
QMUILog.d(TAG, "Can not find " + clsName);
}
return null;
}
@Override
protected View onCreateView() {
FragmentContainerView rootView = new FragmentContainerView(getContext());
rootView.setId(getContextViewId());
return rootView;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mContainerView = view.findViewById(getContextViewId());
if(mContainerView == null){
throw new RuntimeException("must call #configFragmentContainerView() in onCreateView()");
}
}
protected void configFragmentContainerView(FragmentContainerView fragmentContainerView){
fragmentContainerView.setId(getContextViewId());
}
@Override
public void onDestroyView() {
super.onDestroyView();
mContainerView = null;
}
@Override
public int getContextViewId() {
return R.id.qmui_activity_fragment_container_id;
}
View on GitHub (pinned to 026e7d4866)
Solutions
- Inflate a layout containing a FragmentContainerView and override configFragmentContainerView() to set its id to getContextViewId().
- Ensure onCreateView() calls super (or reproduces QMUINavFragment's inflation) before onViewCreated runs.
- Replace a plain container (FrameLayout/LinearLayout) with androidx.fragment.app.FragmentContainerView in the layout XML.
- Give the container exactly the id returned by getContextViewId() (e.g. via fragmentContainerView.setId(getContextViewId())).
Example fix
// before (layout)
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"/>
// after
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_fragment_container_view"
android:layout_width="match_parent" android:layout_height="match_parent"/>
// in fragment
@Override
protected void configFragmentContainerView(FragmentContainerView v) {
v.setId(getContextViewId());
} Defensive patterns
Strategy: validation
Validate before calling
View container = view.findViewById(getContextViewId());
if (!(container instanceof FragmentContainerView)) {
throw new IllegalStateException("QMUINavFragment layout must contain a FragmentContainerView with the configured id");
} Type guard
boolean hasNavContainer(View root, int id) {
return root.findViewById(id) instanceof FragmentContainerView;
} Try / catch
try {
navFragment.onViewCreated(view, savedInstanceState);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("configFragmentContainerView")) {
Log.e(TAG, "nav fragment layout missing FragmentContainerView", e);
} else throw e;
} Prevention
- Always include FragmentContainerView in QMUINavFragment layouts
- Override configFragmentContainerView() and set the id to getContextViewId()
- Never skip super.onCreateView() in subclasses
When it happens
Trigger: Subclassing QMUINavFragment and inflating a layout that either lacks a FragmentContainerView, gives it a different id, or where the subclass never calls configFragmentContainerView() in onCreateView; also overriding onCreateView without calling super and without wiring the container.
Common situations: Custom nav-fragment layouts that use plain FrameLayout instead of FragmentContainerView, ids changed during redesign, or copy-pasted onCreateView implementations that skip the config hook.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- Can not find the fragment container provider.
- ViewPager with adapter %s requires a view id
- the view create by onCreateContentView() should implement fr
- Can not perform LatestVisitRecord, %s must be annotated by L
- Fragment(%s) not attached to Activity.
AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06).
Data as JSON: /api/errors/f627c8b96add2958.
Report an issue: GitHub.