upgrading app getting Error inflating class com.google.android.material.navigation.NavigationView

huangapple go评论99阅读模式
英文:

upgrading app getting Error inflating class com.google.android.material.navigation.NavigationView

问题

  1. **错误信息**
  2. E/AndroidRuntime: 致命异常: 主线程
  3. 进程: com.example.bagexpres, 进程ID: 8603
  4. java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.example.bagexpres/com.example.bagexpres.Main2Activity}: android.view.InflateException: 二进制 XML 文件第 59 行: 二进制 XML 文件第 59 行: com.google.android.material.navigation.NavigationView 中膨胀错误
  5. ...(以下为堆栈跟踪)
  6. **XML 布局**
  7. 布局的 XML 如下
  8. <?xml version="1.0" encoding="utf-8"?>
  9. <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  10. xmlns:app="http://schemas.android.com/apk/res-auto"
  11. xmlns:tools="http://schemas.android.com/tools"
  12. android:layout_width="match_parent"
  13. android:layout_height="match_parent"
  14. tools:context=".Main2Activity"
  15. android:id="@+id/drawerLayout">
  16. <androidx.constraintlayout.widget.ConstraintLayout
  17. android:layout_width="match_parent"
  18. android:layout_height="match_parent">
  19. <!-- 其他布局元素 -->
  20. </androidx.constraintlayout.widget.ConstraintLayout>
  21. <com.google.android.material.navigation.NavigationView
  22. android:id="@+id/navigationView"
  23. android:layout_width="wrap_content"
  24. android:layout_height="match_parent"
  25. app:headerLayout="@layout/layout_navigation_header"
  26. app:menu="@menu/navigation_menu"
  27. app:itemTextColor="@color/bPrimaryDark"
  28. android:layout_gravity="start"/>
  29. </androidx.drawerlayout.widget.DrawerLayout>
  30. **导航菜单**
  31. 导航菜单如下
  32. <?xml version="1.0" encoding="utf-8"?>
  33. <menu xmlns:android="http://schemas.android.com/apk/res/android">
  34. <item
  35. android:id="@+id/menuProfile"
  36. android:title="@string/profile"/>
  37. <!-- 其他菜单项 -->
  38. </menu>
  39. **导航头部布局**
  40. 导航头部布局如下
  41. <?xml version="1.0" encoding="utf-8"?>
  42. <ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  43. xmlns:app="http://schemas.android.com/apk/res-auto"
  44. android:layout_width="match_parent"
  45. android:layout_height="200dp"
  46. android:padding="20dp">
  47. <!-- 其他布局元素 -->
  48. </ConstraintLayout>
  49. **Gradle 配置**
  50. Gradle 配置如下
  51. apply plugin: 'com.android.application'
  52. apply plugin: 'com.google.gms.google-services'
  53. android {
  54. compileSdkVersion 30
  55. buildToolsVersion "30.0.2"
  56. defaultConfig {
  57. applicationId "com.example.bxpr"
  58. minSdkVersion 19
  59. targetSdkVersion 30
  60. versionCode 1
  61. versionName "1.0"
  62. multiDexEnabled true
  63. // 其他配置项
  64. }
  65. buildTypes {
  66. release {
  67. // 其他发布配置项
  68. }
  69. }
  70. }
  71. dependencies {
  72. implementation fileTree(dir: "libs", include: ["*.jar"])
  73. // 其他依赖项
  74. implementation 'com.android.support:multidex:1.0.3'
  75. implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1'
  76. implementation 'androidx.navigation:navigation-ui-ktx:2.3.1'
  77. implementation 'com.google.android.material:material:1.3.0-alpha03'
  78. implementation 'com.makeramen:roundedimageview:2.3.0'
  79. }

请注意,上述内容只是您提供的信息的翻译,可能不包含任何额外的解释或回答。如有需要,请随时提问。

英文:

I am trying to convert an old project and getting this error, have wasted so much time but not getting anywhere really appreciate if someone can help. Thanks in advance

Error

  1. E/AndroidRuntime: FATAL EXCEPTION: main
  2. Process: com.example.bagexpres, PID: 8603
  3. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bagexpres/com.example.bagexpres.Main2Activity}: android.view.InflateException: Binary XML file line #59: Binary XML file line #59: Error inflating class com.google.android.material.navigation.NavigationView
  4. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2835)
  5. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2913)
  6. at android.app.ActivityThread.-wrap11(Unknown Source:0)
  7. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1615)
  8. at android.os.Handler.dispatchMessage(Handler.java:106)
  9. at android.os.Looper.loop(Looper.java:164)
  10. at android.app.ActivityThread.main(ActivityThread.java:6687)
  11. at java.lang.reflect.Method.invoke(Native Method)
  12. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
  13. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
  14. Caused by: android.view.InflateException: Binary XML file line #59: Binary XML file line #59: Error inflating class com.google.android.material.navigation.NavigationView
  15. Caused by: android.view.InflateException: Binary XML file line #59: Error inflating class com.google.android.material.navigation.NavigationView
  16. Caused by: java.lang.reflect.InvocationTargetException
  17. at java.lang.reflect.Constructor.newInstance0(Native Method)
  18. at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
  19. at android.view.LayoutInflater.createView(LayoutInflater.java:647)
  20. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
  21. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
  22. at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
  23. at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
  24. at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
  25. at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
  26. at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
  27. at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
  28. at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
  29. at com.example.bagexpres.Main2Activity.onCreate(Main2Activity.java:25)
  30. at android.app.Activity.performCreate(Activity.java:7028)
  31. at android.app.Activity.performCreate(Activity.java:7019)
  32. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
  33. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2788)
  34. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2913)
  35. at android.app.ActivityThread.-wrap11(Unknown Source:0)
  36. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1615)
  37. at android.os.Handler.dispatchMessage(Handler.java:106)
  38. at android.os.Looper.loop(Looper.java:164)
  39. at android.app.ActivityThread.main(ActivityThread.java:6687)
  40. at java.lang.reflect.Method.invoke(Native Method)
  41. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
  42. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
  43. Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class ConstraintLayout
  44. Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class ConstraintLayout
  45. Caused by: java.lang.ClassNotFoundException: Didn&#39;t find class &quot;android.view.ConstraintLayout&quot; on path: DexPathList[[zip file &quot;/data/app/com.example.bagexpres-60BGCJxbDuEGgGkaZ5XejQ==/base.apk&quot;],nativeLibraryDirectories=[/data/app/com.example.bxpr-60BGCJxbDuEGgGkaZ5XejQ==/lib/arm, /system/lib, /system/vendor/lib]]
  46. at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
  47. at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
  48. at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
  49. at android.view.LayoutInflater.createView(LayoutInflater.java:606)
  50. E/AndroidRuntime: at android.view.LayoutInflater.onCreateView(LayoutInflater.java:703)
  51. at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
  52. at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
  53. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
  54. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
  55. at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
  56. at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
  57. at com.google.android.material.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:222)
  58. at com.google.android.material.navigation.NavigationView.inflateHeaderView(NavigationView.java:387)
  59. at com.google.android.material.navigation.NavigationView.&lt;init&gt;(NavigationView.java:241)
  60. at com.google.android.material.navigation.NavigationView.&lt;init&gt;(NavigationView.java:122)
  61. at java.lang.reflect.Constructor.newInstance0(Native Method)
  62. at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
  63. at android.view.LayoutInflater.createView(LayoutInflater.java:647)
  64. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
  65. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
  66. at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
  67. at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
  68. at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
  69. at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
  70. at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
  71. at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
  72. at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
  73. at com.example.bagexpres.Main2Activity.onCreate(Main2Activity.java:25)
  74. at android.app.Activity.performCreate(Activity.java:7028)
  75. at android.app.Activity.performCreate(Activity.java:7019)
  76. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
  77. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2788)
  78. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2913)
  79. at android.app.ActivityThread.-wrap11(Unknown Source:0)
  80. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1615)
  81. at android.os.Handler.dispatchMessage(Handler.java:106)
  82. at android.os.Looper.loop(Looper.java:164)
  83. at android.app.ActivityThread.main(ActivityThread.java:6687)
  84. at java.lang.reflect.Method.invoke(Native Method)
  85. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
  86. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)

XML As Below XML of my layout is as below

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  2. &lt;androidx.drawerlayout.widget.DrawerLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  3. xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  4. xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  5. android:layout_width=&quot;match_parent&quot;
  6. android:layout_height=&quot;match_parent&quot;
  7. tools:context=&quot;.Main2Activity&quot;
  8. android:id=&quot;@+id/drawerLayout&quot;&gt;
  9. &lt;androidx.constraintlayout.widget.ConstraintLayout
  10. android:layout_width=&quot;match_parent&quot;
  11. android:layout_height=&quot;match_parent&quot;&gt;
  12. &lt;LinearLayout
  13. android:id=&quot;@+id/layouttoolbar&quot;
  14. android:layout_width=&quot;match_parent&quot;
  15. android:layout_height=&quot;30dp&quot;
  16. android:background=&quot;@color/bPrimary&quot;
  17. android:gravity=&quot;center_vertical&quot;
  18. android:orientation=&quot;horizontal&quot;
  19. android:paddingStart=&quot;15dp&quot;
  20. android:paddingEnd=&quot;15dp&quot;
  21. app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  22. &lt;ImageView
  23. android:id=&quot;@+id/imageMenu&quot;
  24. android:layout_width=&quot;40dp&quot;
  25. android:layout_height=&quot;40dp&quot;
  26. android:contentDescription=&quot;@string/app_name&quot;
  27. android:src=&quot;@drawable/ic_menu&quot;
  28. android:backgroundTint=&quot;@color/bWhite&quot;/&gt;
  29. &lt;TextView
  30. android:id=&quot;@+id/textTitle&quot;
  31. android:layout_width=&quot;match_parent&quot;
  32. android:layout_height=&quot;wrap_content&quot;
  33. android:layout_marginStart=&quot;15dp&quot;
  34. android:text=&quot;@string/app_name&quot;
  35. android:textColor=&quot;@color/bWhite&quot;
  36. android:textSize=&quot;18sp&quot;
  37. android:textStyle=&quot;bold&quot;/&gt;
  38. &lt;/LinearLayout&gt;
  39. &lt;fragment
  40. android:layout_width=&quot;match_parent&quot;
  41. android:layout_height=&quot;0dp&quot;
  42. app:layout_constraintTop_toBottomOf=&quot;@id/layouttoolbar&quot;
  43. app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
  44. android:id=&quot;@+id/navhostfragment&quot;
  45. android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
  46. app:defaultNavHost=&quot;true&quot;
  47. app:navGraph=&quot;@navigation/main&quot;/&gt;
  48. &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  49. &lt;com.google.android.material.navigation.NavigationView
  50. android:id=&quot;@+id/navigationView&quot;
  51. android:layout_width=&quot;wrap_content&quot;
  52. android:layout_height=&quot;match_parent&quot;
  53. app:headerLayout=&quot;@layout/layout_navigation_header&quot;
  54. app:menu=&quot;@menu/navigation_menu&quot;
  55. app:itemTextColor=&quot;@color/bPrimaryDark&quot;
  56. android:layout_gravity=&quot;start&quot;/&gt;
  57. &lt;/androidx.drawerlayout.widget.DrawerLayout&gt;

Navigation Menu Navigation Menu is as under

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  2. &lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
  3. &lt;item
  4. android:id=&quot;@+id/menuProfile&quot;
  5. android:title=&quot;@string/profile&quot;/&gt;
  6. &lt;item
  7. android:id=&quot;@+id/menuNotification&quot;
  8. android:title=&quot;@string/notification&quot;/&gt;
  9. &lt;item
  10. android:id=&quot;@+id/menuBookNow&quot;
  11. android:title=&quot;@string/booknow&quot;/&gt;
  12. &lt;item
  13. android:id=&quot;@+id/menuOrder&quot;
  14. android:title=&quot;@string/order&quot;/&gt;
  15. &lt;item
  16. android:id=&quot;@+id/menuPayments&quot;
  17. android:icon=&quot;@drawable/ic_payment&quot;
  18. android:title=&quot;@string/account_balance&quot;/&gt;
  19. &lt;item android:title=&quot;@string/others&quot;&gt;
  20. &lt;menu&gt;
  21. &lt;item
  22. android:id=&quot;@+id/menuSetting&quot;
  23. android:title=&quot;@string/setting&quot;/&gt;
  24. &lt;item
  25. android:id=&quot;@+id/menuSupport&quot;
  26. android:title=&quot;@string/support&quot;/&gt;
  27. &lt;item
  28. android:id=&quot;@+id/menuLogout&quot;
  29. android:title=&quot;@string/logout&quot;/&gt;
  30. &lt;/menu&gt;
  31. &lt;/item&gt;
  32. &lt;/menu&gt;

Navigation Header Navigation layout as below

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  2. &lt;ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  3. xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  4. android:layout_width=&quot;match_parent&quot;
  5. android:layout_height=&quot;200dp&quot;
  6. android:padding=&quot;20dp&quot;&gt;
  7. &lt;RoundedImageView
  8. android:id=&quot;@+id/imageProfile&quot;
  9. android:layout_width=&quot;100dp&quot;
  10. android:layout_height=&quot;100dp&quot;
  11. android:scaleType=&quot;centerCrop&quot;
  12. android:src=&quot;@drawable/splash2&quot;
  13. app:layout_constraintStart_toStartOf=&quot;parent&quot;
  14. app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  15. &lt;View
  16. android:id=&quot;@+id/viewSupporter&quot;
  17. android:layout_width=&quot;1dp&quot;
  18. android:layout_height=&quot;1dp&quot;
  19. app:layout_constraintBottom_toBottomOf=&quot;@id/imageProfile&quot;
  20. app:layout_constraintEnd_toEndOf=&quot;@id/imageProfile&quot;
  21. app:layout_constraintStart_toStartOf=&quot;@id/imageProfile&quot;
  22. app:layout_constraintTop_toTopOf=&quot;@+id/imageProfile&quot; /&gt;
  23. &lt;TextView
  24. android:layout_width=&quot;0dp&quot;
  25. android:layout_height=&quot;wrap_content&quot;
  26. android:layout_marginStart=&quot;10dp&quot;
  27. android:hint=&quot;Username&quot;
  28. android:textColor=&quot;@color/bPrimary&quot;
  29. android:textSize=&quot;18sp&quot;
  30. android:textStyle=&quot;bold&quot;
  31. app:layout_constraintBottom_toTopOf=&quot;@id/viewSupporter&quot;
  32. app:layout_constraintStart_toEndOf=&quot;@id/imageProfile&quot;
  33. android:id=&quot;@+id/username&quot;/&gt;
  34. &lt;TextView
  35. android:layout_width=&quot;0dp&quot;
  36. android:layout_height=&quot;wrap_content&quot;
  37. android:layout_marginStart=&quot;10dp&quot;
  38. android:text=&quot;@string/verified&quot;
  39. android:textColor=&quot;@color/bGreen&quot;
  40. android:textSize=&quot;16sp&quot;
  41. app:layout_constraintStart_toEndOf=&quot;@id/imageProfile&quot;
  42. app:layout_constraintTop_toBottomOf=&quot;@id/viewSupporter&quot; /&gt;
  43. &lt;View
  44. android:layout_width=&quot;match_parent&quot;
  45. android:layout_height=&quot;2dp&quot;
  46. android:background=&quot;@color/bGreen&quot;
  47. android:foregroundGravity=&quot;bottom&quot;
  48. android:paddingBottom=&quot;10dp&quot;
  49. app:layout_constraintTop_toBottomOf=&quot;@id/imageProfile&quot; /&gt;
  50. &lt;/ConstraintLayout&gt;

Gradle this is my gradle

  1. apply plugin: &#39;com.android.application&#39;
  2. apply plugin: &#39;com.google.gms.google-services&#39;
  3. android {
  4. compileSdkVersion 30
  5. buildToolsVersion &quot;30.0.2&quot;
  6. defaultConfig {
  7. applicationId &quot;com.example.bxpr&quot;
  8. minSdkVersion 19
  9. targetSdkVersion 30
  10. versionCode 1
  11. versionName &quot;1.0&quot;
  12. multiDexEnabled true
  13. testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
  14. }
  15. buildTypes {
  16. release {
  17. minifyEnabled false
  18. proguardFiles getDefaultProguardFile(&#39;proguard-android-optimize.txt&#39;), &#39;proguard-rules.pro&#39;
  19. }
  20. }
  21. }
  22. dependencies {
  23. implementation fileTree(dir: &quot;libs&quot;, include: [&quot;*.jar&quot;])
  24. implementation &#39;androidx.appcompat:appcompat:1.2.0&#39;
  25. implementation &#39;androidx.constraintlayout:constraintlayout:2.0.2&#39;
  26. implementation &#39;com.google.firebase:firebase-auth:19.4.0&#39;
  27. implementation &#39;com.google.firebase:firebase-firestore:21.7.1&#39;
  28. implementation &#39;androidx.legacy:legacy-support-v4:1.0.0&#39;
  29. testImplementation &#39;junit:junit:4.12&#39;
  30. androidTestImplementation &#39;androidx.test.ext:junit:1.1.2&#39;
  31. androidTestImplementation &#39;androidx.test.espresso:espresso-core:3.3.0&#39;
  32. implementation &#39;com.android.support:multidex:1.0.3&#39;
  33. //Navigation Component
  34. implementation &#39;androidx.navigation:navigation-fragment-ktx:2.3.1&#39;
  35. implementation &#39;androidx.navigation:navigation-ui-ktx:2.3.1&#39;
  36. // Material Design
  37. implementation &#39;com.google.android.material:material:1.3.0-alpha03&#39;
  38. // Rounded Image View
  39. implementation &#39;com.makeramen:roundedimageview:2.3.0&#39;
  40. }

答案1

得分: 1

> 由以下原因引起:java.lang.ClassNotFoundException: 没有找到类"android.view.ConstraintLayout"

问题出在您的 layout/layout_navigation_header 中。

请使用

  1. androidx.constraintlayout.widget.ConstraintLayout

替代

  1. ConstraintLayout
英文:

> Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.ConstraintLayout"

The issue is in your layout/layout_navigation_header

Use

  1. androidx.constraintlayout.widget.ConstraintLayout

instead of

  1. ConstraintLayout

huangapple
  • 本文由 发表于 2020年10月22日 02:05:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/64469281.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定