{"record":{"id":"f627c8b96add2958","repo":"Tencent/QMUI_Android","slug":"must-call-configfragmentcontainerview-in-oncrea","errorCode":null,"errorMessage":"must call #configFragmentContainerView() in onCreateView()","messagePattern":"must call #configFragmentContainerView\\(\\) in onCreateView\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"arch/src/main/java/com/qmuiteam/qmui/arch/QMUINavFragment.java","lineNumber":115,"sourceCode":"        } catch (ClassNotFoundException e) {\n            QMUILog.d(TAG, \"Can not find \" + clsName);\n        }\n        return null;\n    }\n\n    @Override\n    protected View onCreateView() {\n        FragmentContainerView rootView = new FragmentContainerView(getContext());\n        rootView.setId(getContextViewId());\n        return rootView;\n    }\n\n    @Override\n    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {\n        super.onViewCreated(view, savedInstanceState);\n        mContainerView = view.findViewById(getContextViewId());\n        if(mContainerView == null){\n            throw new RuntimeException(\"must call #configFragmentContainerView() in onCreateView()\");\n        }\n    }\n\n    protected void configFragmentContainerView(FragmentContainerView fragmentContainerView){\n        fragmentContainerView.setId(getContextViewId());\n    }\n\n    @Override\n    public void onDestroyView() {\n        super.onDestroyView();\n        mContainerView = null;\n    }\n\n    @Override\n    public int getContextViewId() {\n        return R.id.qmui_activity_fragment_container_id;\n    }\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/arch/src/main/java/com/qmuiteam/qmui/arch/QMUINavFragment.java#L97-L133","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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()))."],"exampleFix":"// before (layout)\n<FrameLayout android:layout_width=\"match_parent\" android:layout_height=\"match_parent\"/>\n// after\n<androidx.fragment.app.FragmentContainerView\n    android:id=\"@+id/nav_fragment_container_view\"\n    android:layout_width=\"match_parent\" android:layout_height=\"match_parent\"/>\n// in fragment\n@Override\nprotected void configFragmentContainerView(FragmentContainerView v) {\n    v.setId(getContextViewId());\n}","handlingStrategy":"validation","validationCode":"View container = view.findViewById(getContextViewId());\nif (!(container instanceof FragmentContainerView)) {\n    throw new IllegalStateException(\"QMUINavFragment layout must contain a FragmentContainerView with the configured id\");\n}","typeGuard":"boolean hasNavContainer(View root, int id) {\n    return root.findViewById(id) instanceof FragmentContainerView;\n}","tryCatchPattern":"try {\n    navFragment.onViewCreated(view, savedInstanceState);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"configFragmentContainerView\")) {\n        Log.e(TAG, \"nav fragment layout missing FragmentContainerView\", e);\n    } else throw e;\n}","preventionTips":["Always include FragmentContainerView in QMUINavFragment layouts","Override configFragmentContainerView() and set the id to getContextViewId()","Never skip super.onCreateView() in subclasses"],"tags":["android","fragment","navigation","layout"],"backgroundTag":"missing-required-config","analyzedSha":"026e7d486677d6593a96689cd590ec3561176717","analyzedAt":"2026-09-06T13:32:24.816Z","contentChangedAt":"2026-09-06T13:32:24.816Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}