Tencent/QMUI_Android · error · IllegalStateException

Use addContentView(View, QMUIPriorityLinearLayout.LayoutPara

Error message

Use addContentView(View, QMUIPriorityLinearLayout.LayoutParams) for replacement

What it means

The three-argument form of content setting is likewise forbidden: QMUIBottomSheet.setContentView(View, ViewGroup.LayoutParams) always throws IllegalStateException and points you to addContentView(View, QMUIPriorityLinearLayout.LayoutParams), matching the internal priority-linear layout used for the sheet's content stack.

Source

Thrown at qmui/src/main/java/com/qmuiteam/qmui/widget/dialog/QMUIBottomSheet.java:261

    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(
                "Use addContentView(View, QMUIPriorityLinearLayout.LayoutParams) for replacement");
    }

    public void addContentView(View view, QMUIPriorityLinearLayout.LayoutParams layoutParams) {
        mRootView.addView(view, layoutParams);
    }

    public void addContentView(View view) {
        QMUIPriorityLinearLayout.LayoutParams lp =  new QMUIPriorityLinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.setPriority(QMUIPriorityLinearLayout.LayoutParams.PRIORITY_DISPOSABLE);
        mRootView.addView(view, lp);

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Use addContentView(view, new QMUIPriorityLinearLayout.LayoutParams(width, height)) with QMUIPriorityLinearLayout.LayoutParams instead of generic params.
  2. Prefer the QMUIBottomSheet builder API (addView/addTopView) for composing content.
  3. Route shared dialog helpers around QMUIBottomSheet-specific content methods.
  4. Note the QMUIBottomSheet.addContentView(View, ViewGroup.LayoutParams) is itself unsupported here — use the QMUIPriorityLinearLayout.LayoutParams overload specifically.

Example fix

// before
bottomSheet.setContentView(view, new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT)); // throws
// after
bottomSheet.addContentView(view, new QMUIPriorityLinearLayout.LayoutParams(
        QMUIPriorityLinearLayout.LayoutParams.MATCH_PARENT,
        QMUIPriorityLinearLayout.LayoutParams.WRAP_CONTENT));
Defensive patterns

Strategy: try-catch

Validate before calling

if (sheet instanceof QMUIBottomSheet && !(params instanceof QMUIPriorityLinearLayout.LayoutParams)) {
    params = new QMUIPriorityLinearLayout.LayoutParams(params.width, params.height);
}

Type guard

boolean usesQmuiParams(ViewGroup.LayoutParams p) { return p instanceof QMUIPriorityLinearLayout.LayoutParams; }

Try / catch

try {
    sheet.setContentView(view, params);
} catch (IllegalStateException e) {
    sheet.addContentView(view, new QMUIPriorityLinearLayout.LayoutParams(params.width, params.height));
}

Prevention

When it happens

Trigger: Calling bottomSheet.setContentView(view, layoutParams) with any ViewGroup.LayoutParams on a QMUIBottomSheet.

Common situations: Generic dialog code that passes custom LayoutParams, or framework-level wrappers invoking Dialog.setContentView(view, params) programmatically.

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/5b1205bbb5f7a99d. Report an issue: GitHub.