umano/AndroidSlidingUpPanel · error · java.lang.IllegalStateException

Width must have an exact value or MATCH_PARENT

Error message

Width must have an exact value or MATCH_PARENT

What it means

During onMeasure, SlidingUpPanelLayout requires its width measure spec to be EXACTLY or AT_MOST. If the parent measures it UNSPECIFIED (e.g. wrap_content inside certain parents), it throws IllegalStateException because panel positioning math needs a concrete width.

Solutions

  1. Set layout_width to match_parent or a fixed dp value in XML
  2. If programmatic, measure with MeasureSpec.EXACTLY or AT_MOST
  3. Remove wrapping scroll containers that don't impose a bounded width

Example fix

// before
<com.sothree.slidinguppanel.SlidingUpPanelLayout
    android:layout_width="wrap_content" ... />
// after
<com.sothree.slidinguppanel.SlidingUpPanelLayout
    android:layout_width="match_parent" ... />
Defensive patterns

Strategy: validation

Validate before calling

ViewGroup.LayoutParams lp = layout.getLayoutParams();
if (lp != null && lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) lp.width = ViewGroup.LayoutParams.MATCH_PARENT;

Prevention

When it happens

Trigger: Laying out SlidingUpPanelLayout with wrap_content width inside a parent that generates UNSPECIFIED/loose specs, or placing it in containers like ScrollView/LinearLayout with wrap_content that don't provide exact bounds.

Common situations: XML layout where the SlidingUpPanelLayout root has layout_width="wrap_content", or embedding it in a horizontally scrolling container.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of umano/AndroidSlidingUpPanel@45a460435b (2026-09-11). Data as JSON: /api/errors/1e181300cf05dc23. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java:732

        super.onAttachedToWindow();
        mFirstLayout = true;
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mFirstLayout = true;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        final int heightSize = MeasureSpec.getSize(heightMeasureSpec);

        if (widthMode != MeasureSpec.EXACTLY && widthMode != MeasureSpec.AT_MOST) {
            throw new IllegalStateException("Width must have an exact value or MATCH_PARENT");
        } else if (heightMode != MeasureSpec.EXACTLY && heightMode != MeasureSpec.AT_MOST) {
            throw new IllegalStateException("Height must have an exact value or MATCH_PARENT");
        }

        final int childCount = getChildCount();

        if (childCount != 2) {
            throw new IllegalStateException("Sliding up panel layout must have exactly 2 children!");
        }

        mMainView = getChildAt(0);
        mSlideableView = getChildAt(1);
        if (mDragView == null) {
            setDragView(mSlideableView);
        }

        // If the sliding panel is not visible, then put the whole view in the hidden state
        if (mSlideableView.getVisibility() != VISIBLE) {

View on GitHub (pinned to 45a460435b)