{"record":{"id":"40b23f757db298c4","repo":"Tencent/QMUI_Android","slug":"use-addcontentview-view-constraintlayout-layoutpa","errorCode":null,"errorMessage":"Use addContentView(View, ConstraintLayout.LayoutParams) for replacement","messagePattern":"Use addContentView\\(View, ConstraintLayout\\.LayoutParams\\) for replacement","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/widget/dialog/QMUIBottomSheet.java","lineNumber":249,"sourceCode":"        mAnimateToDismiss = false;\n    }\n\n    protected void setToExpandWhenShow(){\n        mRootView.postOnAnimation(new Runnable() {\n            @Override\n            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(","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/widget/dialog/QMUIBottomSheet.java#L231-L267","documentation":"QMUIBottomSheet builds its content with ConstraintLayout internally, so overriding Dialog's setContentView(View) is intentionally disabled and always throws IllegalStateException, directing you to addContentView(View, ConstraintLayout.LayoutParams) instead.","triggerScenarios":"Calling bottomSheet.setContentView(someView) on a QMUIBottomSheet instance, or code shared with regular Dialogs that calls setContentView unconditionally.","commonSituations":"Reusing dialog-building helper code written for AlertDialog/Dialog, or migrating an existing Dialog to QMUIBottomSheet without changing content-setup calls.","solutions":["Replace setContentView(view) with bottomSheet.addContentView(view, new ConstraintLayout.LayoutParams(matchParent or MATCH_PARENT, WRAP_CONTENT)) as appropriate.","Use the QMUIBottomSheet builder API (createBottomSheetBuilder().addView(...)) instead of setting content directly.","Update shared dialog helpers to branch on QMUIBottomSheet and use addContentView.","Read the exception hint: each overload names the exact replacement method to use."],"exampleFix":"// before\nbottomSheet.setContentView(myView); // throws\n// after\nConstraintLayout.LayoutParams lp = new ConstraintLayout.LayoutParams(\n        ConstraintLayout.LayoutParams.MATCH_PARENT,\n        ConstraintLayout.LayoutParams.WRAP_CONTENT);\nbottomSheet.addContentView(myView, lp);","handlingStrategy":"try-catch","validationCode":"if (sheet instanceof QMUIBottomSheet) {\n    // use addContentView(view, ConstraintLayout.LayoutParams) or the builder\n}","typeGuard":"boolean supportsSetContentView(Dialog d) { return !(d instanceof QMUIBottomSheet); }","tryCatchPattern":"try {\n    sheet.setContentView(view);\n} catch (IllegalStateException e) {\n    sheet.addContentView(view, new ConstraintLayout.LayoutParams(\n            ConstraintLayout.LayoutParams.MATCH_PARENT,\n            ConstraintLayout.LayoutParams.WRAP_CONTENT));\n}","preventionTips":["Never call setContentView on QMUIBottomSheet; use the builder API or addContentView.","Abstract dialog-content setup behind a helper that switches on the dialog type.","When migrating Dialog/AlertDialog code to QMUIBottomSheet, grep for setContentView calls.","Prefer createBottomSheetBuilder().addView(...) for all sheet content."],"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"}