Tencent/QMUI_Android · error · RuntimeException

you should call view() to set your content view

Error message

you should call view() to set your content view

What it means

QMUINormalPopup.show(anchor, ...) throws a RuntimeException when mContentView is null, i.e. view() was never called to supply the popup's content. The popup cannot compute its window size or position without content.

Source

Thrown at qmui/src/main/java/com/qmuiteam/qmui/widget/popup/QMUINormalPopup.java:363

            return x - anchorRootLocation[0];
        }

        int getWindowY() {
            return y - anchorRootLocation[1];
        }
    }

    private boolean shouldShowShadow() {
        return mAddShadow && QMUILayoutHelper.useFeature();
    }

    public T show(@NonNull View anchor) {
        return show(anchor, 0, 0, anchor.getWidth(), anchor.getHeight());
    }

    public T show(@NonNull View anchor, int anchorAreaLeft, int anchorAreaTop, int anchorAreaRight, int anchorAreaBottom){
        if (mContentView == null) {
            throw new RuntimeException("you should call view() to set your content view");
        }
        decorateContentView();
        ShowInfo showInfo = new ShowInfo(anchor, anchorAreaLeft, anchorAreaTop, anchorAreaRight, anchorAreaBottom);
        calculateWindowSize(showInfo);
        calculateXY(showInfo);
        adjustShowInfo(showInfo);
        mDecorRootView.setShowInfo(showInfo);
        setAnimationStyle(showInfo.anchorProportion(), showInfo.direction);
        mWindow.setWidth(showInfo.windowWidth());
        mWindow.setHeight(showInfo.windowHeight());
        showAtLocation(anchor, showInfo.getWindowX(), showInfo.getWindowY());
        return (T) this;
    }

    private void decorateContentView() {
        ContentView contentView = ContentView.wrap(mContentView, mInitWidth, mInitHeight);
        QMUISkinValueBuilder builder = QMUISkinValueBuilder.acquire();
        if (mIsBorderColorSet) {

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Call popup.view(contentView) before popup.show(anchor).
  2. If content is built asynchronously, defer show() until the content view is ready.
  3. Guard the show() call with a null check on the content you intend to pass.

Example fix

// before
QMUINormalPopup popup = QMUINormalPopup.create(context);
popup.show(anchor); // crashes: content not set
// after
QMUINormalPopup popup = QMUINormalPopup.create(context)
        .view(R.layout.popup_content);
popup.show(anchor);
Defensive patterns

Strategy: validation

Validate before calling

if (contentView != null) {
    popup.view(contentView).show(anchor);
}

Try / catch

try {
    popup.show(anchor);
} catch (RuntimeException e) {
    Log.e(TAG, "call view() before show() on QMUINormalPopup", e);
}

Prevention

When it happens

Trigger: Calling popup.show(anchor) (any overload) before popup.view(contentView) has been invoked; reusing a popup builder instance where the view() call was skipped or the content view was never assigned.

Common situations: Showing the popup from a click handler while configuration happens asynchronously later; forgetting view() because another popup type (e.g. fullscreen popup) uses addView() instead.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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