material-components/material-components-android · error · IllegalArgumentException
Transient bottom bar must have non-null parent
Error message
Transient bottom bar must have non-null parent
What it means
IllegalArgumentException from the BaseTransientBottomBar constructor when the parent ViewGroup is null. The parameter is annotated @NonNull, but runtime checks still exist for callers that bypass null-safety (Java without lint, reflection, or Kotlin with platform types), making the failure explicit instead of an NPE later at addView time.
Source
Thrown at lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java:355
*
* @param parent The parent for this transient bottom bar.
* @param content The content view for this transient bottom bar.
* @param contentViewCallback The content view callback for this transient bottom bar.
*/
protected BaseTransientBottomBar(
@NonNull ViewGroup parent,
@NonNull View content,
@NonNull com.google.android.material.snackbar.ContentViewCallback contentViewCallback) {
this(parent.getContext(), parent, content, contentViewCallback);
}
protected BaseTransientBottomBar(
@NonNull Context context,
@NonNull ViewGroup parent,
@NonNull View content,
@NonNull com.google.android.material.snackbar.ContentViewCallback contentViewCallback) {
if (parent == null) {
throw new IllegalArgumentException("Transient bottom bar must have non-null parent");
}
if (content == null) {
throw new IllegalArgumentException("Transient bottom bar must have non-null content");
}
if (contentViewCallback == null) {
throw new IllegalArgumentException("Transient bottom bar must have non-null callback");
}
targetParent = parent;
this.contentViewCallback = contentViewCallback;
this.context = context;
ThemeEnforcement.checkAppCompatTheme(context);
LayoutInflater inflater = LayoutInflater.from(context);
// Note that for backwards compatibility reasons we inflate a layout that is defined
// in the extending Snackbar class. This is to prevent breakage of apps that have custom
// coordinator layout behaviors that depend on that layout.View on GitHub (pinned to ac7e18efee)
Solutions
- Resolve the parent view from a live hierarchy: use the content view or a CoordinatorLayout that is definitely attached.
- Guard: if (parent != null) showTransient(parent) else fallback to a dialog/toast.
- In fragments, wait for onViewCreated and use the fragment's view as the parent.
Example fix
// before Snackbar.make(findViewById(R.id.missing), "hi", LENGTH_SHORT).show(); // parent null // after View parent = findViewById(android.R.id.content); if (parent != null) Snackbar.make(parent, "hi", LENGTH_SHORT).show();
Defensive patterns
Strategy: validation
Validate before calling
View parent = findViewById(android.R.id.content);
if (parent instanceof ViewGroup) {
Snackbar.make((ViewGroup) parent, text, Snackbar.LENGTH_SHORT).show();
} Prevention
- Use android.R.id.content or a known-attached CoordinatorLayout as the parent.
- In fragments, show transients from onViewCreated, not onCreate.
- Skip showing transient bars on finishing activities.
When it happens
Trigger: Passing a null parent to Snackbar.make(...), a custom BaseTransientBottomBar subclass constructor, or supplying findViewById(...) that returned null (though that usually surfaces via error 159 for anchors — here it is the parent itself).
Common situations: Showing a snackbar before the view hierarchy exists (e.g. in onCreate before setContentView), using an activity that is finishing, or custom transients built with reflection/dependency injection where the parent was not resolved.
Related errors
- Transient bottom bar must have non-null content
- Transient bottom bar must have non-null callback
- Unable to find anchor view with id:
- At least one value must be set
- The continuousModeTickCount(%s) must be greater than or equa
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/ce15e25e2aff0613.
Report an issue: GitHub.