{"record":{"id":"ce15e25e2aff0613","repo":"material-components/material-components-android","slug":"transient-bottom-bar-must-have-non-null-parent","errorCode":null,"errorMessage":"Transient bottom bar must have non-null parent","messagePattern":"Transient bottom bar must have non-null parent","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java","lineNumber":355,"sourceCode":"   *\n   * @param parent The parent for this transient bottom bar.\n   * @param content The content view for this transient bottom bar.\n   * @param contentViewCallback The content view callback for this transient bottom bar.\n   */\n  protected BaseTransientBottomBar(\n      @NonNull ViewGroup parent,\n      @NonNull View content,\n      @NonNull com.google.android.material.snackbar.ContentViewCallback contentViewCallback) {\n    this(parent.getContext(), parent, content, contentViewCallback);\n  }\n\n  protected BaseTransientBottomBar(\n      @NonNull Context context,\n      @NonNull ViewGroup parent,\n      @NonNull View content,\n      @NonNull com.google.android.material.snackbar.ContentViewCallback contentViewCallback) {\n    if (parent == null) {\n      throw new IllegalArgumentException(\"Transient bottom bar must have non-null parent\");\n    }\n    if (content == null) {\n      throw new IllegalArgumentException(\"Transient bottom bar must have non-null content\");\n    }\n    if (contentViewCallback == null) {\n      throw new IllegalArgumentException(\"Transient bottom bar must have non-null callback\");\n    }\n\n    targetParent = parent;\n    this.contentViewCallback = contentViewCallback;\n    this.context = context;\n\n    ThemeEnforcement.checkAppCompatTheme(context);\n\n    LayoutInflater inflater = LayoutInflater.from(context);\n    // Note that for backwards compatibility reasons we inflate a layout that is defined\n    // in the extending Snackbar class. This is to prevent breakage of apps that have custom\n    // coordinator layout behaviors that depend on that layout.","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java#L337-L373","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nSnackbar.make(findViewById(R.id.missing), \"hi\", LENGTH_SHORT).show(); // parent null\n\n// after\nView parent = findViewById(android.R.id.content);\nif (parent != null) Snackbar.make(parent, \"hi\", LENGTH_SHORT).show();","handlingStrategy":"validation","validationCode":"View parent = findViewById(android.R.id.content);\nif (parent instanceof ViewGroup) {\n  Snackbar.make((ViewGroup) parent, text, Snackbar.LENGTH_SHORT).show();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["android","snackbar","material-components","null-safety","immediate"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}