material-components/material-components-android · error · IllegalArgumentException
The view is not associated with ExpandableBehavior
Error message
The view is not associated with ExpandableBehavior
What it means
ExpandableBehavior.from(view, klass) (ExpandableBehavior.java:174) second check: the view is a CoordinatorLayout child, but the LayoutParams' behavior is either null or not an ExpandableBehavior. Behaviors are declared per-child via app:layout_behavior or set programmatically with CoordinatorLayout.LayoutParams.setBehavior(); without one, there is nothing to retrieve and the cast cannot proceed, so IllegalArgumentException is thrown.
Source
Thrown at lib/java/com/google/android/material/transformation/ExpandableBehavior.java:174
}
/**
* A utility function to get the {@link ExpandableBehavior} attached to the {@code view}.
*
* @param view The {@link View} that the {@link ExpandableBehavior} is attached to.
* @param klass The expected {@link Class} of the attached {@link ExpandableBehavior}.
* @return The {@link ExpandableBehavior} attached to the {@code view}.
*/
@Nullable
public static <T extends ExpandableBehavior> T from(@NonNull View view, @NonNull Class<T> klass) {
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 ExpandableBehavior)) {
throw new IllegalArgumentException("The view is not associated with ExpandableBehavior");
}
return klass.cast(behavior);
}
}
View on GitHub (pinned to ac7e18efee)
Solutions
- Add app:layout_behavior pointing to your ExpandableBehavior subclass on the view, e.g. app:layout_behavior="com.google.android.material.transformation.ExpandableTransformationBehavior".
- Or set it in code: ((CoordinatorLayout.LayoutParams) view.getLayoutParams()).setBehavior(new FabTransformationBehavior());
- Check the fully-qualified class string for typos — an unresolvable behavior string silently leaves no behavior set.
Example fix
<!-- before -->
<View android:id="+id/card"
android:layout_width="match_parent" android:layout_height="200dp" />
<!-- after -->
<View android:id="+id/card"
android:layout_width="match_parent" android:layout_height="200dp"
app:layout_behavior="com.google.android.material.transformation.FabTransformationBehavior" /> Defensive patterns
Strategy: validation
Validate before calling
boolean hasExpandableBehavior(View v) {
ViewGroup.LayoutParams p = v.getLayoutParams();
return p instanceof CoordinatorLayout.LayoutParams
&& ((CoordinatorLayout.LayoutParams) p).getBehavior() instanceof ExpandableBehavior;
}
ExpandableBehavior b = hasExpandableBehavior(v) ? ExpandableBehavior.from(v, ExpandableBehavior.class) : null; Type guard
@Nullable
static ExpandableBehavior resolveIfExpandable(@NonNull View v) {
if (!(v.getLayoutParams() instanceof CoordinatorLayout.LayoutParams)) return null;
CoordinatorLayout.Behavior<?> behavior =
((CoordinatorLayout.LayoutParams) v.getLayoutParams()).getBehavior();
return behavior instanceof ExpandableBehavior ? (ExpandableBehavior) behavior : null;
} Prevention
- Always declare app:layout_behavior with the fully-qualified ExpandableBehavior subclass on CoordinatorLayout children.
- Test transformation setup in a UI test that inflates the real layout.
- Add a debug assertion after inflation that getBehavior() is non-null for transformation views.
When it happens
Trigger: Calling from() on a CoordinatorLayout child that has no app:layout_behavior attribute; a behavior set via setBehavior() with a non-ExpandableBehavior type (e.g. BottomSheetBehavior, AppBarLayout.ScrollingViewBehavior); typo in the app:layout_behavior class string so the default null/other behavior resolves.
Common situations: Adding a view inside CoordinatorLayout (fixing error 182) but forgetting to declare app:layout_behavior on it; copy-pasting a layout_behavior string from another component (e.g. bottom sheet) instead of the expandable transformation behavior class.
Related errors
- The view is not a child of CoordinatorLayout
- The view is not a child of CoordinatorLayout
- The view is not associated with SideSheetBehavior
- This behavior cannot be attached to a GONE view. Set the vie
- secondaryIconGravity cannot have the same alignment as iconG
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/9e4fb2925b69c3ca.
Report an issue: GitHub.