material-components/material-components-android · error · IllegalStateException
Sheet view reference is null; sheet edge cannot be changed i
Error message
Sheet view reference is null; sheet edge cannot be changed if the sheet view is null.
What it means
SheetDialog.setSheetEdge() throws IllegalStateException when the internal sheet view reference is null — i.e. the dialog's content view (and thus the sheet) has not been created yet. The method needs a real sheet view to adjust its CoordinatorLayout.LayoutParams gravity; the Javadoc states it must be called when the sheet is initialized, before it is shown.
Source
Thrown at lib/java/com/google/android/material/sidesheet/SheetDialog.java:343
}
return super.performAccessibilityAction(host, action, args);
}
});
return container;
}
/**
* Set the edge which the sheet should originate from.
*
* <p>Note: This method should be called when the sheet is initialized, before it is shown.
* Runtime sheet edge changes are not supported.
*
* @throws IllegalStateException if the sheet is null or has already been laid out
* @param gravity the edge from which the sheet and its animations should originate.
*/
public void setSheetEdge(@GravityInt int gravity) {
if (sheet == null) {
throw new IllegalStateException(
"Sheet view reference is null; sheet edge cannot be changed if the sheet view is null.");
}
if (sheet.isLaidOut()) {
throw new IllegalStateException(
"Sheet view has been laid out; sheet edge cannot be changed once the sheet has been laid"
+ " out.");
}
ViewGroup.LayoutParams layoutParams = sheet.getLayoutParams();
if (layoutParams instanceof CoordinatorLayout.LayoutParams) {
((CoordinatorLayout.LayoutParams) layoutParams).gravity = gravity;
maybeUpdateWindowAnimationsBasedOnLayoutDirection();
}
}
private void maybeUpdateWindowAnimationsBasedOnLayoutDirection() {
Window window = getWindow();
if (window != null
&& sheet != nullView on GitHub (pinned to ac7e18efee)
Solutions
- Call setSheetEdge() after the sheet exists — e.g. inside your dialog's onCreate() after setContentView(...), or immediately after show() but before the sheet has been laid out.
- Or set the edge declaratively so no runtime call is needed (the default right-edge behavior), and only override gravity before layout.
- Guard with a null check: if (dialog.getSheet() != null) { dialog.setSheetEdge(gravity); } else { defer via dialog.setOnShowListener(...); }
Example fix
// before val dialog = SideSheetDialog(context) dialog.setSheetEdge(Gravity.LEFT) // sheet == null, throws dialog.show() // after val dialog = SideSheetDialog(context) dialog.show() dialog.setSheetEdge(Gravity.LEFT) // sheet exists, not yet laid out
Defensive patterns
Strategy: validation
Validate before calling
if (dialog.findViewById(com.google.android.material.R.id.m3_side_sheet) != null) {
dialog.setSheetEdge(gravity);
} else {
dialog.setOnShowListener(d -> dialog.setSheetEdge(gravity));
dialog.show();
} Prevention
- Treat setSheetEdge as a create-time call: configure it right after show() or in onCreate() after setContentView().
- Never call sheet APIs on a dialog that has not been shown.
When it happens
Trigger: Calling sideSheetDialog.setSheetEdge(Gravity.LEFT) immediately after constructing the SheetDialog, before show()/setContentView() have inflated the sheet layout into the dialog window.
Common situations: Configuring a freshly constructed SideSheetDialog in a builder function that runs before show(); extracting the sheet edge to a helper called from onCreate() before super.onCreate() inflates content; refactoring dialog setup code so the edge call happens too early.
Related errors
- Sheet view has been laid out; sheet edge cannot be changed o
- The view is not associated with SideSheetBehavior
- dateSelector should not be null. Use MaterialTextInputPicker
- Invalid sheet edge position value: %d. Must be %d or %d.
- Unexpected value: %s
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/24b26a1db6216a61.
Report an issue: GitHub.