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

The view is not a child of CoordinatorLayout

Error message

The view is not a child of CoordinatorLayout

What it means

SideSheetBehavior.from(view) throws IllegalArgumentException when the view's LayoutParams are not CoordinatorLayout.LayoutParams — i.e. the view is not a direct child of a CoordinatorLayout. from() reads the behavior off the child's layout params, so a view inflated elsewhere (LinearLayout, FragmentContainer, Dialog) fails this check before behavior lookup.

Source

Thrown at lib/java/com/google/android/material/sidesheet/SideSheetBehavior.java:1169

          @Override
          public SavedState[] newArray(int size) {
            return new SavedState[size];
          }
        };
  }

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

  private void updateAccessibilityActions() {
    if (viewRef == null) {
      return;
    }
    V child = viewRef.get();
    if (child == null) {
      return;
    }
    ViewCompat.removeAccessibilityAction(child, AccessibilityNodeInfoCompat.ACTION_EXPAND);
    ViewCompat.removeAccessibilityAction(child, AccessibilityNodeInfoCompat.ACTION_DISMISS);

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Move the sheet view so it is a direct child of the CoordinatorLayout.
  2. Apply app:layout_behavior="com.google.android.material.sidesheet.SideSheetBehavior" on that direct child.
  3. If you only have a nested reference, resolve the CoordinatorLayout child first (e.g. (CoordinatorLayout) view.getParent().getParent()) and call from() on the right view.

Example fix

<!-- before -->
<CoordinatorLayout ...>
    <LinearLayout ...>
        <View android:id="@+id/sheet" />
    </LinearLayout>
</CoordinatorLayout>

<!-- after -->
<CoordinatorLayout ...>
    <LinearLayout android:id="@+id/sheet"
        app:layout_behavior="com.google.android.material.sidesheet.SideSheetBehavior" />
</CoordinatorLayout>
Defensive patterns

Strategy: type-guard

Validate before calling

View directChild = sheetView;
ViewParent p = sheetView.getParent();
if (p instanceof CoordinatorLayout) {
  SideSheetBehavior<View> b = SideSheetBehavior.from(sheetView);
} else {
  throw new IllegalStateException("Sheet must be a direct child of CoordinatorLayout");
}

Type guard

static boolean isCoordinatorLayoutChild(View v) {
  return v.getLayoutParams() instanceof CoordinatorLayout.LayoutParams;
}

Prevention

When it happens

Trigger: Calling SideSheetBehavior.from(findViewById(R.id.sheet)) when the sheet view is nested inside another container (e.g. a LinearLayout inside CoordinatorLayout, or placed in a ConstraintLayout) instead of being a direct child of CoordinatorLayout.

Common situations: Wrapping the sheet in an extra container 'for spacing'; moving layouts during refactors so the sheet is no longer a direct CoordinatorLayout child; dialog content where the root is not a CoordinatorLayout.

Related errors


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