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

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

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

问题

**错误信息**
E/AndroidRuntime: 致命异常: 主线程
    进程: com.example.bagexpres, 进程ID: 8603
    java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.example.bagexpres/com.example.bagexpres.Main2Activity}: android.view.InflateException: 二进制 XML 文件第 59 行: 二进制 XML 文件第 59 行: 在 com.google.android.material.navigation.NavigationView 中膨胀错误
    ...(以下为堆栈跟踪)

**XML 布局**
布局的 XML 如下

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main2Activity"
    android:id="@+id/drawerLayout">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- 其他布局元素 -->

    </androidx.constraintlayout.widget.ConstraintLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/navigationView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:headerLayout="@layout/layout_navigation_header"
        app:menu="@menu/navigation_menu"
        app:itemTextColor="@color/bPrimaryDark"
        android:layout_gravity="start"/>

</androidx.drawerlayout.widget.DrawerLayout>

**导航菜单**
导航菜单如下

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/menuProfile"
         android:title="@string/profile"/>

    <!-- 其他菜单项 -->

</menu>

**导航头部布局**
导航头部布局如下

<?xml version="1.0" encoding="utf-8"?>
<ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:padding="20dp">

    <!-- 其他布局元素 -->

</ConstraintLayout>

**Gradle 配置**
Gradle 配置如下

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.bxpr"
        minSdkVersion 19
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

        // 其他配置项
    }

    buildTypes {
        release {
            // 其他发布配置项
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    // 其他依赖项

    implementation 'com.android.support:multidex:1.0.3'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.1'
    implementation 'com.google.android.material:material:1.3.0-alpha03'
    implementation 'com.makeramen:roundedimageview:2.3.0'
}

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

英文:

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

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bagexpres, PID: 8603
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
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2835)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1615)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6687)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
Caused by: android.view.InflateException: Binary XML file line #59: Binary XML file line #59: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #59: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.bagexpres.Main2Activity.onCreate(Main2Activity.java:25)
at android.app.Activity.performCreate(Activity.java:7028)
at android.app.Activity.performCreate(Activity.java:7019)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2788)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1615)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6687)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class ConstraintLayout
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]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
E/AndroidRuntime:     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:703)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.google.android.material.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:222)
at com.google.android.material.navigation.NavigationView.inflateHeaderView(NavigationView.java:387)
at com.google.android.material.navigation.NavigationView.&lt;init&gt;(NavigationView.java:241)
at com.google.android.material.navigation.NavigationView.&lt;init&gt;(NavigationView.java:122)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.bagexpres.Main2Activity.onCreate(Main2Activity.java:25)
at android.app.Activity.performCreate(Activity.java:7028)
at android.app.Activity.performCreate(Activity.java:7019)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2788)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1615)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6687)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)

XML As Below XML of my layout is as below

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;androidx.drawerlayout.widget.DrawerLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
tools:context=&quot;.Main2Activity&quot;
android:id=&quot;@+id/drawerLayout&quot;&gt;
&lt;androidx.constraintlayout.widget.ConstraintLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;&gt;
&lt;LinearLayout
android:id=&quot;@+id/layouttoolbar&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;30dp&quot;
android:background=&quot;@color/bPrimary&quot;
android:gravity=&quot;center_vertical&quot;
android:orientation=&quot;horizontal&quot;
android:paddingStart=&quot;15dp&quot;
android:paddingEnd=&quot;15dp&quot;
app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
&lt;ImageView
android:id=&quot;@+id/imageMenu&quot;
android:layout_width=&quot;40dp&quot;
android:layout_height=&quot;40dp&quot;
android:contentDescription=&quot;@string/app_name&quot;
android:src=&quot;@drawable/ic_menu&quot;
android:backgroundTint=&quot;@color/bWhite&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/textTitle&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginStart=&quot;15dp&quot;
android:text=&quot;@string/app_name&quot;
android:textColor=&quot;@color/bWhite&quot;
android:textSize=&quot;18sp&quot;
android:textStyle=&quot;bold&quot;/&gt;
&lt;/LinearLayout&gt;
&lt;fragment
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;0dp&quot;
app:layout_constraintTop_toBottomOf=&quot;@id/layouttoolbar&quot;
app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
android:id=&quot;@+id/navhostfragment&quot;
android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
app:defaultNavHost=&quot;true&quot;
app:navGraph=&quot;@navigation/main&quot;/&gt;
&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
&lt;com.google.android.material.navigation.NavigationView
android:id=&quot;@+id/navigationView&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;match_parent&quot;
app:headerLayout=&quot;@layout/layout_navigation_header&quot;
app:menu=&quot;@menu/navigation_menu&quot;
app:itemTextColor=&quot;@color/bPrimaryDark&quot;
android:layout_gravity=&quot;start&quot;/&gt;
&lt;/androidx.drawerlayout.widget.DrawerLayout&gt;

Navigation Menu Navigation Menu is as under

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
&lt;item
android:id=&quot;@+id/menuProfile&quot;
android:title=&quot;@string/profile&quot;/&gt;
&lt;item
android:id=&quot;@+id/menuNotification&quot;
android:title=&quot;@string/notification&quot;/&gt;
&lt;item
android:id=&quot;@+id/menuBookNow&quot;
android:title=&quot;@string/booknow&quot;/&gt;
&lt;item
android:id=&quot;@+id/menuOrder&quot;
android:title=&quot;@string/order&quot;/&gt;
&lt;item
android:id=&quot;@+id/menuPayments&quot;
android:icon=&quot;@drawable/ic_payment&quot;
android:title=&quot;@string/account_balance&quot;/&gt;
&lt;item android:title=&quot;@string/others&quot;&gt;
&lt;menu&gt;
&lt;item
android:id=&quot;@+id/menuSetting&quot;
android:title=&quot;@string/setting&quot;/&gt;
&lt;item
android:id=&quot;@+id/menuSupport&quot;
android:title=&quot;@string/support&quot;/&gt;
&lt;item
android:id=&quot;@+id/menuLogout&quot;
android:title=&quot;@string/logout&quot;/&gt;
&lt;/menu&gt;
&lt;/item&gt;
&lt;/menu&gt;

Navigation Header Navigation layout as below

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;200dp&quot;
android:padding=&quot;20dp&quot;&gt;
&lt;RoundedImageView
android:id=&quot;@+id/imageProfile&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:scaleType=&quot;centerCrop&quot;
android:src=&quot;@drawable/splash2&quot;
app:layout_constraintStart_toStartOf=&quot;parent&quot;
app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
&lt;View
android:id=&quot;@+id/viewSupporter&quot;
android:layout_width=&quot;1dp&quot;
android:layout_height=&quot;1dp&quot;
app:layout_constraintBottom_toBottomOf=&quot;@id/imageProfile&quot;
app:layout_constraintEnd_toEndOf=&quot;@id/imageProfile&quot;
app:layout_constraintStart_toStartOf=&quot;@id/imageProfile&quot;
app:layout_constraintTop_toTopOf=&quot;@+id/imageProfile&quot; /&gt;
&lt;TextView
android:layout_width=&quot;0dp&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginStart=&quot;10dp&quot;
android:hint=&quot;Username&quot;
android:textColor=&quot;@color/bPrimary&quot;
android:textSize=&quot;18sp&quot;
android:textStyle=&quot;bold&quot;
app:layout_constraintBottom_toTopOf=&quot;@id/viewSupporter&quot;
app:layout_constraintStart_toEndOf=&quot;@id/imageProfile&quot;
android:id=&quot;@+id/username&quot;/&gt;
&lt;TextView
android:layout_width=&quot;0dp&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginStart=&quot;10dp&quot;
android:text=&quot;@string/verified&quot;
android:textColor=&quot;@color/bGreen&quot;
android:textSize=&quot;16sp&quot;
app:layout_constraintStart_toEndOf=&quot;@id/imageProfile&quot;
app:layout_constraintTop_toBottomOf=&quot;@id/viewSupporter&quot; /&gt;
&lt;View
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;2dp&quot;
android:background=&quot;@color/bGreen&quot;
android:foregroundGravity=&quot;bottom&quot;
android:paddingBottom=&quot;10dp&quot;
app:layout_constraintTop_toBottomOf=&quot;@id/imageProfile&quot; /&gt;
&lt;/ConstraintLayout&gt;

Gradle this is my gradle

apply plugin: &#39;com.android.application&#39;
apply plugin: &#39;com.google.gms.google-services&#39;
android {
compileSdkVersion 30
buildToolsVersion &quot;30.0.2&quot;
defaultConfig {
applicationId &quot;com.example.bxpr&quot;
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName &quot;1.0&quot;
multiDexEnabled true
testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(&#39;proguard-android-optimize.txt&#39;), &#39;proguard-rules.pro&#39;
}
}
}
dependencies {
implementation fileTree(dir: &quot;libs&quot;, include: [&quot;*.jar&quot;])
implementation &#39;androidx.appcompat:appcompat:1.2.0&#39;
implementation &#39;androidx.constraintlayout:constraintlayout:2.0.2&#39;
implementation &#39;com.google.firebase:firebase-auth:19.4.0&#39;
implementation &#39;com.google.firebase:firebase-firestore:21.7.1&#39;
implementation &#39;androidx.legacy:legacy-support-v4:1.0.0&#39;
testImplementation &#39;junit:junit:4.12&#39;
androidTestImplementation &#39;androidx.test.ext:junit:1.1.2&#39;
androidTestImplementation &#39;androidx.test.espresso:espresso-core:3.3.0&#39;
implementation &#39;com.android.support:multidex:1.0.3&#39;
//Navigation Component
implementation &#39;androidx.navigation:navigation-fragment-ktx:2.3.1&#39;
implementation &#39;androidx.navigation:navigation-ui-ktx:2.3.1&#39;
// Material Design
implementation &#39;com.google.android.material:material:1.3.0-alpha03&#39;
// Rounded Image View
implementation &#39;com.makeramen:roundedimageview:2.3.0&#39;
}

答案1

得分: 1

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

问题出在您的 layout/layout_navigation_header 中。

请使用

androidx.constraintlayout.widget.ConstraintLayout

替代

ConstraintLayout
英文:

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

The issue is in your layout/layout_navigation_header

Use

androidx.constraintlayout.widget.ConstraintLayout

instead of

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:

确定