umano/AndroidSlidingUpPanel · error · java.lang.IllegalStateException

Sliding up panel layout must have exactly 2 children!

Error message

Sliding up panel layout must have exactly 2 children!

What it means

Thrown from onMeasure() during layout when the SlidingUpPanelLayout's XML (or programmatic) child count is not exactly 2. This custom ViewGroup's design requires precisely two children: the main (scrollable) content view and the slide-up panel view, whose positions and dragged offsets are computed by index in onMeasure/onLayout. It fires when a developer adds one, three, or more children (extra padding views, include tags, wrappers, or programmatically added views) instead of the required main-content + panel pair. Fix: keep exactly two direct children — the main content first and the sliding panel second.

Solutions

  1. Ensure exactly two direct children: main view first, slideable panel second
  2. Move extra views inside one of the two children
  3. Remove runtime addView() calls on this layout, or wrap additions inside the panel child

Example fix

// before
<SlidingUpPanelLayout>
    <TextView/> <!-- only 1 child -->
</SlidingUpPanelLayout>
// after
<SlidingUpPanelLayout>
    <LinearLayout>...</LinearLayout> <!-- main -->
    <LinearLayout>...</LinearLayout> <!-- panel -->
</SlidingUpPanelLayout>
Defensive patterns

Strategy: validation

Validate before calling

if (layout.getChildCount() != 2) {
    throw new IllegalStateException("SlidingUpPanelLayout needs exactly 2 children, has " + layout.getChildCount());
}

Prevention

When it happens

Trigger: Declaring the layout in XML with 1 child (only main or only panel), 3+ children, or adding children at runtime via addView().

Common situations: Merging fragments/views directly into the layout with the merge tag collapsing children count, or a data-binding/include adding an extra wrapper child.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

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

    }

    @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) {
            mSlideState = PanelState.HIDDEN;
        }

        int layoutHeight = heightSize - getPaddingTop() - getPaddingBottom();
        int layoutWidth = widthSize - getPaddingLeft() - getPaddingRight();

        // First pass. Measure based on child LayoutParams width/height.
        for (int i = 0; i < childCount; i++) {

View on GitHub (pinned to 45a460435b)