{"record":{"id":"87a50588a691caf2","repo":"umano/AndroidSlidingUpPanel","slug":"sliding-up-panel-layout-must-have-exactly-2-childr","errorCode":null,"errorMessage":"Sliding up panel layout must have exactly 2 children!","messagePattern":"Sliding up panel layout must have exactly 2 children!","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java","lineNumber":740,"sourceCode":"    }\n\n    @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);\n        final int widthSize = MeasureSpec.getSize(widthMeasureSpec);\n        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);\n        final int heightSize = MeasureSpec.getSize(heightMeasureSpec);\n\n        if (widthMode != MeasureSpec.EXACTLY && widthMode != MeasureSpec.AT_MOST) {\n            throw new IllegalStateException(\"Width must have an exact value or MATCH_PARENT\");\n        } else if (heightMode != MeasureSpec.EXACTLY && heightMode != MeasureSpec.AT_MOST) {\n            throw new IllegalStateException(\"Height must have an exact value or MATCH_PARENT\");\n        }\n\n        final int childCount = getChildCount();\n\n        if (childCount != 2) {\n            throw new IllegalStateException(\"Sliding up panel layout must have exactly 2 children!\");\n        }\n\n        mMainView = getChildAt(0);\n        mSlideableView = getChildAt(1);\n        if (mDragView == null) {\n            setDragView(mSlideableView);\n        }\n\n        // If the sliding panel is not visible, then put the whole view in the hidden state\n        if (mSlideableView.getVisibility() != VISIBLE) {\n            mSlideState = PanelState.HIDDEN;\n        }\n\n        int layoutHeight = heightSize - getPaddingTop() - getPaddingBottom();\n        int layoutWidth = widthSize - getPaddingLeft() - getPaddingRight();\n\n        // First pass. Measure based on child LayoutParams width/height.\n        for (int i = 0; i < childCount; i++) {","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/umano/AndroidSlidingUpPanel/blob/45a460435b07e764138a700328836cafc1ed5c42/library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java#L722-L758","documentation":"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.","triggerScenarios":"Declaring the layout in XML with 1 child (only main or only panel), 3+ children, or adding children at runtime via addView().","commonSituations":"Merging fragments/views directly into the layout with the merge tag collapsing children count, or a data-binding/include adding an extra wrapper child.","solutions":["Ensure exactly two direct children: main view first, slideable panel second","Move extra views inside one of the two children","Remove runtime addView() calls on this layout, or wrap additions inside the panel child"],"exampleFix":"// before\n<SlidingUpPanelLayout>\n    <TextView/> <!-- only 1 child -->\n</SlidingUpPanelLayout>\n// after\n<SlidingUpPanelLayout>\n    <LinearLayout>...</LinearLayout> <!-- main -->\n    <LinearLayout>...</LinearLayout> <!-- panel -->\n</SlidingUpPanelLayout>","handlingStrategy":"validation","validationCode":"if (layout.getChildCount() != 2) {\n    throw new IllegalStateException(\"SlidingUpPanelLayout needs exactly 2 children, has \" + layout.getChildCount());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep exactly two direct XML children (main first, panel second)","Avoid merge tags that alter child count","Don't addView() directly to this layout"],"tags":["android","layout","child-count"],"backgroundTag":"schema-validation-failed","analyzedSha":"45a460435b07e764138a700328836cafc1ed5c42","analyzedAt":"2026-09-11T10:02:33.403Z","contentChangedAt":"2026-09-11T10:02:33.403Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}