{"record":{"id":"9e4fb2925b69c3ca","repo":"material-components/material-components-android","slug":"the-view-is-not-associated-with-expandablebehavior","errorCode":null,"errorMessage":"The view is not associated with ExpandableBehavior","messagePattern":"The view is not associated with ExpandableBehavior","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/transformation/ExpandableBehavior.java","lineNumber":174,"sourceCode":"  }\n\n  /**\n   * A utility function to get the {@link ExpandableBehavior} attached to the {@code view}.\n   *\n   * @param view The {@link View} that the {@link ExpandableBehavior} is attached to.\n   * @param klass The expected {@link Class} of the attached {@link ExpandableBehavior}.\n   * @return The {@link ExpandableBehavior} attached to the {@code view}.\n   */\n  @Nullable\n  public static <T extends ExpandableBehavior> T from(@NonNull View view, @NonNull Class<T> klass) {\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 ExpandableBehavior)) {\n      throw new IllegalArgumentException(\"The view is not associated with ExpandableBehavior\");\n    }\n    return klass.cast(behavior);\n  }\n}\n","sourceCodeStart":156,"sourceCodeEnd":179,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/transformation/ExpandableBehavior.java#L156-L179","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"<!-- before -->\n<View android:id=\"+id/card\"\n    android:layout_width=\"match_parent\" android:layout_height=\"200dp\" />\n\n<!-- after -->\n<View android:id=\"+id/card\"\n    android:layout_width=\"match_parent\" android:layout_height=\"200dp\"\n    app:layout_behavior=\"com.google.android.material.transformation.FabTransformationBehavior\" />","handlingStrategy":"validation","validationCode":"boolean hasExpandableBehavior(View v) {\n  ViewGroup.LayoutParams p = v.getLayoutParams();\n  return p instanceof CoordinatorLayout.LayoutParams\n      && ((CoordinatorLayout.LayoutParams) p).getBehavior() instanceof ExpandableBehavior;\n}\nExpandableBehavior b = hasExpandableBehavior(v) ? ExpandableBehavior.from(v, ExpandableBehavior.class) : null;","typeGuard":"@Nullable\nstatic ExpandableBehavior resolveIfExpandable(@NonNull View v) {\n  if (!(v.getLayoutParams() instanceof CoordinatorLayout.LayoutParams)) return null;\n  CoordinatorLayout.Behavior<?> behavior =\n      ((CoordinatorLayout.LayoutParams) v.getLayoutParams()).getBehavior();\n  return behavior instanceof ExpandableBehavior ? (ExpandableBehavior) behavior : null;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["android","material-components","coordinatorlayout","layout-behavior","expandablebehavior"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}