{"record":{"id":"18d368fd2d9f7a15","repo":"Tencent/QMUI_Android","slug":"you-should-call-addview-to-add-content-view","errorCode":null,"errorMessage":"you should call addView() to add content view","messagePattern":"you should call addView\\(\\) to add content view","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/widget/popup/QMUIFullScreenPopup.java","lineNumber":160,"sourceCode":"            QMUISkinValueBuilder builder = QMUISkinValueBuilder.acquire().src(mCloseIconAttr);\n            QMUISkinHelper.setSkinValue(closeBtn, builder);\n            builder.release();\n            drawable = QMUIResHelper.getAttrDrawable(mContext, mCloseIconAttr);\n        }\n        closeBtn.setImageDrawable(drawable);\n        return closeBtn;\n    }\n\n    public boolean isShowing() {\n        return mWindow.isShowing();\n    }\n\n    public void show(View parent) {\n        if (isShowing()) {\n            return;\n        }\n        if (mViews.isEmpty()) {\n            throw new RuntimeException(\"you should call addView() to add content view\");\n        }\n        ArrayList<ViewInfo> views = new ArrayList<>(mViews);\n        RootView rootView = new RootView(mContext);\n        for (int i = 0; i < views.size(); i++) {\n            ViewInfo info = mViews.get(i);\n            View view = info.view;\n            if (view.getParent() != null) {\n                ((ViewGroup) view.getParent()).removeView(view);\n            }\n\n            rootView.addView(view, info.lp);\n        }\n        if (mAddCloseBtn) {\n            if (mCloseIvLayoutParams == null) {\n                mCloseIvLayoutParams = defaultCloseIvLp();\n            }\n            rootView.addView(createCloseIv(), mCloseIvLayoutParams);\n        }","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/widget/popup/QMUIFullScreenPopup.java#L142-L178","documentation":"QMUIFullScreenPopup.show() throws a RuntimeException when the popup's internal view list is empty, meaning addView() was never called before showing. The popup has nothing to display onto the decor view, so it refuses to proceed.","triggerScenarios":"Calling popup.show(parent) without any prior popup.addView(view) (or addView(view, layoutParams)) call; also if show() is called after the popup was cleared/rebuilt and no views were re-added.","commonSituations":"Building the popup conditionally so all addView() calls are skipped; forgetting to add views after copying popup construction code; calling show() from a different code path than the one that configured views.","solutions":["Call popup.addView(contentView) (optionally with LayoutParams) at least once before popup.show(parent).","Add a guard: only call show() if at least one view was added.","Ensure the code path that shows the popup is the same one that populated it."],"exampleFix":"// before\nQMUIFullScreenPopup popup = QMUIFullScreenPopup.create(context);\npopup.show(parent); // crashes: no views added\n// after\nQMUIFullScreenPopup popup = QMUIFullScreenPopup.create(context);\npopup.addView(contentView);\npopup.show(parent);","handlingStrategy":"validation","validationCode":"if (popupHasNoViews) { popup.addView(contentView); }\npopup.show(parent);","typeGuard":null,"tryCatchPattern":"try {\n    popup.show(parent);\n} catch (RuntimeException e) {\n    Log.e(TAG, \"popup had no views; configure addView() before show()\", e);\n}","preventionTips":["Always pair popup creation with at least one addView() call in the same factory/builder function.","Only call show() after content configuration completes (including async paths).","Track a boolean 'configured' flag to gate show()."],"tags":["android","qmui","popup","missing-content"],"backgroundTag":"empty-required-field","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"}