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

  1. Inflate a layout containing a FragmentContainerView and override configFragmentContainerView() to set its id to getContextViewId().
  2. Ensure onCreateView() calls super (or reproduces QMUINavFragment's inflation) before onViewCreated runs.
  3. Replace a plain container (FrameLayout/LinearLayout) with androidx.fragment.app.FragmentContainerView in the layout XML.
  4. 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

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


AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06). Data as JSON: /api/errors/f627c8b96add2958. Report an issue: GitHub.