material-components/material-components-android · error · IllegalStateException
The view is not associated with SideSheetBehavior
Error message
The view is not associated with SideSheetBehavior
What it means
SideSheetDialog.getBehavior() throws IllegalStateException when the Sheet returned by the base SheetDialog is not a SideSheetBehavior. The side-sheet dialog contract guarantees the behavior type; this fails when a custom subclass overrides getBehavior()/getSheet() to return a different Sheet implementation (or a plain BottomSheetDialog is cast to SideSheetDialog).
Source
Thrown at lib/java/com/google/android/material/sidesheet/SideSheetDialog.java:104
}
@StableSheetState
@Override
int getStateOnStart() {
return Sheet.STATE_EXPANDED;
}
/**
* Returns the behavior associated with this {@link SideSheetDialog}. The behavior must always be
* a {@link SideSheetBehavior}; otherwise, this method will throw an {@link
* IllegalStateException}.
*/
@NonNull
@Override
public SideSheetBehavior<? extends View> getBehavior() {
Sheet<SideSheetCallback> sheetBehavior = super.getBehavior();
if (!(sheetBehavior instanceof SideSheetBehavior)) {
throw new IllegalStateException("The view is not associated with SideSheetBehavior");
}
return (SideSheetBehavior<?>) sheetBehavior;
}
}
View on GitHub (pinned to ac7e18efee)
Solutions
- In custom SideSheetDialog subclasses, ensure the behavior applied to the sheet is a SideSheetBehavior (set the sheet's layout_behavior or override getSheetEdge/getBehavior consistently with SideSheetBehavior).
- Do not port BottomSheetDialog overrides onto SideSheetDialog; remove getBehavior() overrides that return other types.
- Use the dialog's own behavior only through SideSheetDialog.getBehavior() without replacing the underlying Sheet.
Example fix
// before
class MyDialog(context: Context) : SideSheetDialog(context) {
override fun getBehavior(): BottomSheetBehavior<FrameLayout> = // wrong type
bottomBehavior
}
// after
class MyDialog(context: Context) : SideSheetDialog(context) {
// no override; sheet uses SideSheetBehavior, getBehavior() returns it safely
} Defensive patterns
Strategy: type-guard
Validate before calling
Sheet<? extends SheetCallback> sheet = dialog.getSheet();
if (sheet instanceof SideSheetBehavior) {
SideSheetBehavior<? extends View> b = dialog.getBehavior();
} Type guard
static boolean dialogHasSideSheetBehavior(SideSheetDialog dialog) {
return dialog.getSheet() instanceof SideSheetBehavior;
} Try / catch
try { dialog.getBehavior().setState(...); } catch (IllegalStateException e) { Log.e(TAG, "Dialog behavior is not a SideSheetBehavior; check subclass overrides", e); } Prevention
- Do not override getBehavior()/getSheet() in SideSheetDialog subclasses with non-side-sheet types.
- Keep one dialog base class per sheet family (bottom vs side); don't share behavior overrides.
When it happens
Trigger: Subclassing SideSheetDialog and overriding getBehavior() (or the sheet creation) to return a custom Sheet/behavior that is not an instance of SideSheetBehavior, then the framework or app code calls getBehavior().
Common situations: Copy-pasted dialog subclass from a BottomSheetDialog example where getBehavior returns BottomSheetBehavior; attempts to reuse a custom SheetDialog base class across bottom and side sheets; mocking in tests returning a generic Sheet.
Related errors
- Sheet view reference is null; sheet edge cannot be changed i
- Sheet view has been laid out; sheet edge cannot be changed o
- Invalid sheet edge position value: %d. Must be %d or %d.
- Unexpected value: %s
- STATE_%s should not be set externally.
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/d71ca08335b1e654.
Report an issue: GitHub.