android runtime_error ai_generated true

android.view.InflateException: Binary XML file line #XX: Error inflating class <unknown>

ID: android/layout-inflater-crash-bad-parameter

Also available as: JSON · Markdown · 中文
90%Fix Rate
87%Confidence
1Evidence
2023-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Android 10 (API 29) active
Android 11 (API 30) active
Android 12 (API 31) active
Android 13 (API 33) active

Root Cause

A layout XML file contains an invalid attribute, missing custom view, or incompatible resource reference that prevents inflation.

generic

中文

布局 XML 文件包含无效属性、缺少自定义视图或不兼容的资源引用,导致无法膨胀。

Official Documentation

https://developer.android.com/reference/android/view/InflateException

Workarounds

  1. 90% success Inspect the layout XML file at the line number indicated in the error. Look for typos in attribute names, missing namespace declarations (e.g., xmlns:app), or incorrect custom view class names. Example: replace 'android:backgroundTint' with 'app:backgroundTint' if using appcompat.
    Inspect the layout XML file at the line number indicated in the error. Look for typos in attribute names, missing namespace declarations (e.g., xmlns:app), or incorrect custom view class names. Example: replace 'android:backgroundTint' with 'app:backgroundTint' if using appcompat.
  2. 85% success Ensure all custom views are properly declared in the XML with their fully qualified class name (e.g., com.example.MyCustomView instead of MyCustomView).
    Ensure all custom views are properly declared in the XML with their fully qualified class name (e.g., com.example.MyCustomView instead of MyCustomView).
  3. 80% success If using a custom view from a library, verify the library is added as a dependency in build.gradle and the view is not conditionally loaded.
    If using a custom view from a library, verify the library is added as a dependency in build.gradle and the view is not conditionally loaded.

中文步骤

  1. 检查错误指示行号的布局 XML 文件,查找属性名称拼写错误、缺少命名空间声明(如 xmlns:app)或不正确的自定义视图类名。例如:如果使用 appcompat,将 'android:backgroundTint' 替换为 'app:backgroundTint'。
  2. 确保所有自定义视图在 XML 中使用完整限定类名声明(例如 com.example.MyCustomView 而不是 MyCustomView)。
  3. 如果使用了库中的自定义视图,请验证该库是否已作为依赖项添加到 build.gradle 中,并且该视图不是条件加载的。

Dead Ends

Common approaches that don't work:

  1. 90% fail

    The error is in the code, not runtime cache; clearing cache doesn't fix invalid XML.

  2. 95% fail

    Reinstallation doesn't change the source code; the same invalid XML will be inflated again.