Tencent/QMUI_Android · error · IllegalStateException
Use addContentView(View, ConstraintLayout.LayoutParams) for
Error message
Use addContentView(View, ConstraintLayout.LayoutParams) for replacement
What it means
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.
Source
Thrown at qmui/src/main/java/com/qmuiteam/qmui/widget/dialog/QMUIBottomSheet.java:249
mAnimateToDismiss = false;
}
protected void setToExpandWhenShow(){
mRootView.postOnAnimation(new Runnable() {
@Override
public void run() {
mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
}
public interface OnBottomSheetShowListener {
void onShow();
}
@Override
public void setContentView(View view) {
throw new IllegalStateException(
"Use addContentView(View, ConstraintLayout.LayoutParams) for replacement");
}
@Override
public void setContentView(int layoutResId) {
throw new IllegalStateException(
"Use addContentView(int) for replacement");
}
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
throw new IllegalStateException(
"Use addContentView(View, QMUIPriorityLinearLayout.LayoutParams) for replacement");
}
@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
throw new IllegalStateException(View on GitHub (pinned to 026e7d4866)
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.
Example fix
// before
bottomSheet.setContentView(myView); // throws
// after
ConstraintLayout.LayoutParams lp = new ConstraintLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT,
ConstraintLayout.LayoutParams.WRAP_CONTENT);
bottomSheet.addContentView(myView, lp); Defensive patterns
Strategy: try-catch
Validate before calling
if (sheet instanceof QMUIBottomSheet) {
// use addContentView(view, ConstraintLayout.LayoutParams) or the builder
} Type guard
boolean supportsSetContentView(Dialog d) { return !(d instanceof QMUIBottomSheet); } Try / catch
try {
sheet.setContentView(view);
} catch (IllegalStateException e) {
sheet.addContentView(view, new ConstraintLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT,
ConstraintLayout.LayoutParams.WRAP_CONTENT));
} Prevention
- 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.
When it happens
Trigger: Calling bottomSheet.setContentView(someView) on a QMUIBottomSheet instance, or code shared with regular Dialogs that calls setContentView unconditionally.
Common situations: Reusing dialog-building helper code written for AlertDialog/Dialog, or migrating an existing Dialog to QMUIBottomSheet without changing content-setup calls.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Use addContentView(int) for replacement
- Use addContentView(View, QMUIPriorityLinearLayout.LayoutPara
- 不支持adjustViewBounds
- Not support the type: %s
- topView must implement from IQMUIContinuousNestedTopView
AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06).
Data as JSON: /api/errors/40b23f757db298c4.
Report an issue: GitHub.