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

  1. Replace setContentView(view) with bottomSheet.addContentView(view, new ConstraintLayout.LayoutParams(matchParent or MATCH_PARENT, WRAP_CONTENT)) as appropriate.
  2. Use the QMUIBottomSheet builder API (createBottomSheetBuilder().addView(...)) instead of setting content directly.
  3. Update shared dialog helpers to branch on QMUIBottomSheet and use addContentView.
  4. 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

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


AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06). Data as JSON: /api/errors/40b23f757db298c4. Report an issue: GitHub.