{"record":{"id":"564798bb5f9131d7","repo":"material-components/material-components-android","slug":"the-view-is-not-a-child-of-coordinatorlayout-564798","errorCode":null,"errorMessage":"The view is not a child of CoordinatorLayout","messagePattern":"The view is not a child of CoordinatorLayout","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java","lineNumber":2467,"sourceCode":"          @Override\n          public SavedState[] newArray(int size) {\n            return new SavedState[size];\n          }\n        };\n  }\n\n  /**\n   * A utility function to get the {@link BottomSheetBehavior} associated with the {@code view}.\n   *\n   * @param view The {@link View} with {@link BottomSheetBehavior}.\n   * @return The {@link BottomSheetBehavior} associated with the {@code view}.\n   */\n  @NonNull\n  @SuppressWarnings(\"unchecked\")\n  public static <V extends View> BottomSheetBehavior<V> from(@NonNull V view) {\n    ViewGroup.LayoutParams params = view.getLayoutParams();\n    if (!(params instanceof CoordinatorLayout.LayoutParams)) {\n      throw new IllegalArgumentException(\"The view is not a child of CoordinatorLayout\");\n    }\n    CoordinatorLayout.Behavior<?> behavior =\n        ((CoordinatorLayout.LayoutParams) params).getBehavior();\n    if (!(behavior instanceof BottomSheetBehavior)) {\n      throw new IllegalArgumentException(\"The view is not associated with BottomSheetBehavior\");\n    }\n    return (BottomSheetBehavior<V>) behavior;\n  }\n\n  /**\n   * Sets whether the BottomSheet should update the accessibility status of its {@link\n   * CoordinatorLayout} siblings when expanded.\n   *\n   * <p>Set this to true if the expanded state of the sheet blocks access to siblings (e.g., when\n   * the sheet expands over the full screen).\n   */\n  public void setUpdateImportantForAccessibilityOnSiblings(\n      boolean updateImportantForAccessibilityOnSiblings) {","sourceCodeStart":2449,"sourceCodeEnd":2485,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java#L2449-L2485","documentation":"BottomSheetBehavior.from(View) retrieves the behavior attached to a view by casting its ViewGroup.LayoutParams to CoordinatorLayout.LayoutParams. If the view's layout params are not that type, the view is not a direct child of a CoordinatorLayout and from() throws IllegalArgumentException.","triggerScenarios":"Calling BottomSheetBehavior.from(bottomSheet) where bottomSheet is inside a NestedScrollView/FrameLayout wrapper, a different parent container, or not yet attached to the hierarchy (generic LayoutParams).","commonSituations":"The sheet view is wrapped in another container for layout reasons; calling from() before the view is laid out (e.g. in Activity.onCreate before setContentView completes, or on a programmatically created view not yet added to the CoordinatorLayout); accessing a sheet from the wrong fragment's view.","solutions":["Make the sheet a direct child of the CoordinatorLayout with app:layout_behavior=\"...BottomSheetBehavior\".","Call from() only after the view is inflated and attached (onCreateOptionsMenu of the fragment / after setContentView).","If wrapping is unavoidable, apply the behavior to the outermost direct child instead and query that view."],"exampleFix":"<!-- before -->\n<androidx.coordinatorlayout.widget.CoordinatorLayout ...>\n  <FrameLayout ...>\n    <LinearLayout android:id=\"+id/bottom_sheet\" ... /> <!-- not a direct child -->\n  </FrameLayout>\n</androidx.coordinatorlayout.widget.CoordinatorLayout>\n\n<!-- after -->\n<androidx.coordinatorlayout.widget.CoordinatorLayout ...>\n  <LinearLayout\n      android:id=\"+id/bottom_sheet\"\n      app:layout_behavior=\"com.google.android.material.bottomsheet.BottomSheetBehavior\"\n      ... />\n</androidx.coordinatorlayout.widget.CoordinatorLayout>","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"private static boolean isCoordinatorChild(View v) {\n  return v.getLayoutParams() instanceof CoordinatorLayout.LayoutParams;\n}\n// usage: if (isCoordinatorChild(sheet)) BottomSheetBehavior.from(sheet);","tryCatchPattern":null,"preventionTips":["Keep the bottom sheet a direct child of CoordinatorLayout.","Query with from() after the view hierarchy is attached."],"tags":["bottomsheet","coordinatorlayout","illegal-argument","view-hierarchy"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}