{"record":{"id":"a2e023d54bd9463e","repo":"material-components/material-components-android","slug":"the-view-is-not-a-child-of-coordinatorlayout-a2e023","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/transformation/ExpandableBehavior.java","lineNumber":169,"sourceCode":"      return currentState == STATE_UNINITIALIZED || currentState == STATE_COLLAPSED;\n    } else {\n      // Can only collapse from expanded state. Uninitialized is equivalent to collapsed state.\n      return currentState == STATE_EXPANDED;\n    }\n  }\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":151,"sourceCodeEnd":179,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/transformation/ExpandableBehavior.java#L151-L179","documentation":"ExpandableBehavior.from(view, klass) (ExpandableBehavior.java:169) retrieves a transformation behavior attached to a view. It first checks whether the view's LayoutParams are CoordinatorLayout.LayoutParams; since behaviors are stored on CoordinatorLayout child params, a view that is not a direct child of a CoordinatorLayout cannot carry a behavior, and the method throws IllegalArgumentException immediately.","triggerScenarios":"Calling ExpandableTransformationBehavior.from() (or subclasses) on a view inflated into a FrameLayout/ConstraintLayout/RecyclerView; calling from() on a view before it is attached/added to the CoordinatorLayout so getLayoutParams() returns a generic ViewGroup.LayoutParams.","commonSituations":"Using ExpansionLayout/FAB transformation patterns where the dependent view (e.g. a toolbar or card meant to expand from a FAB) sits in a different layout container than the CoordinatorLayout; refactoring a layout from CoordinatorLayout to ConstraintLayout while keeping the java call; calling from() in onCreate before the view is added to the hierarchy.","solutions":["Move the view so it is a direct child of the CoordinatorLayout that also hosts the FAB/dependency.","Ensure from() is called only after the view is attached (e.g. in onAttachedToWindow or after setContentView/inflation completes).","If the view must live elsewhere, restructure so the behavior is attached to a CoordinatorLayout child (e.g. an intermediate wrapper inside the CoordinatorLayout)."],"exampleFix":"<!-- before -->\n<androidx.coordinatorlayout.widget.CoordinatorLayout ...>\n  <com.google.android.material.floatingactionbutton.FloatingActionButton ... />\n</androidx.coordinatorlayout.widget.CoordinatorLayout>\n<LinearLayout ...>\n  <View android:id=\"+id/expandable_card\" ... /> <!-- from() crashes -->\n</LinearLayout>\n\n<!-- after -->\n<androidx.coordinatorlayout.widget.CoordinatorLayout ...>\n  <com.google.android.material.floatingactionbutton.FloatingActionButton ... />\n  <View android:id=\"+id/expandable_card\"\n      app:layout_behavior=\"...ExpandableTransformationBehavior\" ... />\n</androidx.coordinatorlayout.widget.CoordinatorLayout>","handlingStrategy":"validation","validationCode":"boolean isCoordinatorChild(View view) {\n  return view.getLayoutParams() instanceof CoordinatorLayout.LayoutParams;\n}\n// guard:\nif (!isCoordinatorChild(v)) {\n  throw new IllegalStateException(v + \" must be a direct child of CoordinatorLayout\");\n}","typeGuard":"static boolean canResolveExpandableBehavior(View v) {\n  ViewGroup.LayoutParams p = v.getLayoutParams();\n  if (!(p instanceof CoordinatorLayout.LayoutParams)) return false;\n  return ((CoordinatorLayout.LayoutParams) p).getBehavior() instanceof ExpandableBehavior;\n}","tryCatchPattern":null,"preventionTips":["Keep the expandable dependency and dependent view siblings inside one CoordinatorLayout.","Call ExpandableBehavior.from() only after the hierarchy is inflated/attached.","Prefer storing the behavior reference yourself at setup time instead of re-resolving via from()."],"tags":["android","material-components","coordinatorlayout","expandablebehavior","view-hierarchy"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}