material-components/material-components-android · error · IllegalArgumentException

The view is not associated with BottomSheetBehavior

Error message

The view is not associated with BottomSheetBehavior

What it means

BottomSheetBehavior.from(View) checks, after confirming CoordinatorLayout.LayoutParams, that the attached behavior is actually a BottomSheetBehavior. If app:layout_behavior is missing or set to another behavior class, the cast is impossible and IllegalArgumentException is thrown with this message.

Source

Thrown at lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java:2472

  }

  /**
   * A utility function to get the {@link BottomSheetBehavior} associated with the {@code view}.
   *
   * @param view The {@link View} with {@link BottomSheetBehavior}.
   * @return The {@link BottomSheetBehavior} associated with the {@code view}.
   */
  @NonNull
  @SuppressWarnings("unchecked")
  public static <V extends View> BottomSheetBehavior<V> from(@NonNull V view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (!(params instanceof CoordinatorLayout.LayoutParams)) {
      throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
    }
    CoordinatorLayout.Behavior<?> behavior =
        ((CoordinatorLayout.LayoutParams) params).getBehavior();
    if (!(behavior instanceof BottomSheetBehavior)) {
      throw new IllegalArgumentException("The view is not associated with BottomSheetBehavior");
    }
    return (BottomSheetBehavior<V>) behavior;
  }

  /**
   * Sets whether the BottomSheet should update the accessibility status of its {@link
   * CoordinatorLayout} siblings when expanded.
   *
   * <p>Set this to true if the expanded state of the sheet blocks access to siblings (e.g., when
   * the sheet expands over the full screen).
   */
  public void setUpdateImportantForAccessibilityOnSiblings(
      boolean updateImportantForAccessibilityOnSiblings) {
    this.updateImportantForAccessibilityOnSiblings = updateImportantForAccessibilityOnSiblings;
  }

  private void updateImportantForAccessibility(boolean expanded) {
    if (viewRef == null) {

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Add app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" to the sheet view.
  2. Verify the class string has no typos and the xmlns:app namespace is declared on the root.
  3. Confirm you are calling from() on the exact view that carries the BottomSheetBehavior, not a sibling or parent.

Example fix

<!-- before -->
<LinearLayout
    android:id="+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" /> <!-- no behavior -->

<!-- after -->
<LinearLayout
    android:id="+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
Defensive patterns

Strategy: type-guard

Type guard

private static boolean hasBottomSheetBehavior(View v) {
  return v.getLayoutParams() instanceof CoordinatorLayout.LayoutParams
      && ((CoordinatorLayout.LayoutParams) v.getLayoutParams()).getBehavior()
          instanceof BottomSheetBehavior;
}

Prevention

When it happens

Trigger: Calling BottomSheetBehavior.from(view) on a CoordinatorLayout child whose app:layout_behavior attribute is absent, misspelled, or points at a different behavior (AppBarLayout.Behavior, HideViewOnScrollBehavior, a custom Behavior).

Common situations: The behavior attribute was lost when moving/refactoring layout XML; a typo in the fully-qualified behavior class name in XML; calling the wrong from() (e.g. BottomSheetBehavior.from on a view carrying Snackbar.Behavior).

Related errors


AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14). Data as JSON: /api/errors/e97eb33520a12c66. Report an issue: GitHub.