{"record":{"id":"83b89ef9863c7e1d","repo":"Tencent/QMUI_Android","slug":"use-addcontentview-int-for-replacement","errorCode":null,"errorMessage":"Use addContentView(int) for replacement","messagePattern":"Use addContentView\\(int\\) for replacement","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/widget/dialog/QMUIBottomSheet.java","lineNumber":255,"sourceCode":"            public void run() {\n                mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);\n            }\n        });\n    }\n\n    public interface OnBottomSheetShowListener {\n        void onShow();\n    }\n\n    @Override\n    public void setContentView(View view) {\n        throw new IllegalStateException(\n                \"Use addContentView(View, ConstraintLayout.LayoutParams) for replacement\");\n    }\n\n    @Override\n    public void setContentView(int layoutResId) {\n        throw new IllegalStateException(\n                \"Use addContentView(int) for replacement\");\n    }\n\n    @Override\n    public void setContentView(View view, ViewGroup.LayoutParams params) {\n        throw new IllegalStateException(\n                \"Use addContentView(View, QMUIPriorityLinearLayout.LayoutParams) for replacement\");\n    }\n\n    @Override\n    public void addContentView(View view, ViewGroup.LayoutParams params) {\n        throw new IllegalStateException(\n                \"Use addContentView(View, QMUIPriorityLinearLayout.LayoutParams) for replacement\");\n    }\n\n    public void addContentView(View view, QMUIPriorityLinearLayout.LayoutParams layoutParams) {\n        mRootView.addView(view, layoutParams);\n    }","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/widget/dialog/QMUIBottomSheet.java#L237-L273","documentation":"Same design as the View overload: QMUIBottomSheet cannot host a raw layout-resource content view, so setContentView(int layoutResId) is overridden to always throw IllegalStateException, telling you to use addContentView(int) (or the builder API) instead.","triggerScenarios":"Calling bottomSheet.setContentView(R.layout.my_content) on a QMUIBottomSheet.","commonSituations":"Porting existing Dialog code that inflates a layout resource, or copy-pasted boilerplate from AlertDialog usage.","solutions":["Inflate the layout yourself and pass the view via addContentView with ConstraintLayout.LayoutParams.","Use the QMUIBottomSheet builder (createBottomSheetBuilder().addView(inflater.inflate(R.layout.my_content, null))) instead.","Call addContentView(view, ConstraintLayout.LayoutParams) with the inflated view.","Refactor helpers to detect QMUIBottomSheet and avoid the forbidden overloads."],"exampleFix":"// before\nbottomSheet.setContentView(R.layout.sheet_content); // throws\n// after\nView view = LayoutInflater.from(context).inflate(R.layout.sheet_content, null);\nbottomSheet.addContentView(view, new ConstraintLayout.LayoutParams(\n        ConstraintLayout.LayoutParams.MATCH_PARENT,\n        ConstraintLayout.LayoutParams.WRAP_CONTENT));","handlingStrategy":"try-catch","validationCode":"if (sheet instanceof QMUIBottomSheet) {\n    View v = LayoutInflater.from(context).inflate(layoutResId, null);\n    sheet.addContentView(v, new ConstraintLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));\n} else {\n    sheet.setContentView(layoutResId);\n}","typeGuard":"boolean supportsSetContentView(Dialog d) { return !(d instanceof QMUIBottomSheet); }","tryCatchPattern":"try {\n    sheet.setContentView(R.layout.sheet_content);\n} catch (IllegalStateException e) {\n    View v = LayoutInflater.from(context).inflate(R.layout.sheet_content, null);\n    sheet.addContentView(v, new ConstraintLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));\n}","preventionTips":["Inflate layout resources yourself and add the view via addContentView or the builder.","Grep for setContentView(R.layout when converting dialogs to QMUIBottomSheet.","Standardize sheet content creation on QMUIBottomSheetBuilder in your codebase.","Read the exception message — it names the exact replacement method."],"tags":["android","qmui","dialog","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}