簡體   English   中英

升級應用程序獲取錯誤膨脹類 com.google.android.material.navigation.NavigationView

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

我正在嘗試轉換一個舊項目並收到此錯誤,浪費了很多時間,但如果有人可以提供幫助,我真的很感激。 提前致謝

錯誤

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't find class "android.view.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.bagexpres-60BGCJxbDuEGgGkaZ5XejQ==/base.apk"],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.<init>(NavigationView.java:241)
        at com.google.android.material.navigation.NavigationView.<init>(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如下我的布局的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">
    
            <LinearLayout
                android:id="@+id/layouttoolbar"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:background="@color/bPrimary"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingStart="15dp"
                android:paddingEnd="15dp"
                app:layout_constraintTop_toTopOf="parent">
    
                <ImageView
                    android:id="@+id/imageMenu"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:contentDescription="@string/app_name"
                    android:src="@drawable/ic_menu"
                    android:backgroundTint="@color/bWhite"/>
    
                <TextView
                    android:id="@+id/textTitle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:text="@string/app_name"
                    android:textColor="@color/bWhite"
                    android:textSize="18sp"
                    android:textStyle="bold"/>
    
            </LinearLayout>
    
    
            <fragment
                android:layout_width="match_parent"
                android:layout_height="0dp"
                app:layout_constraintTop_toBottomOf="@id/layouttoolbar"
                app:layout_constraintBottom_toBottomOf="parent"
                android:id="@+id/navhostfragment"
                android:name="androidx.navigation.fragment.NavHostFragment"
                app:defaultNavHost="true"
                app:navGraph="@navigation/main"/>
    
        </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"/>
    
        <item
            android:id="@+id/menuNotification"
            android:title="@string/notification"/>
    
        <item
            android:id="@+id/menuBookNow"
            android:title="@string/booknow"/>
    
        <item
            android:id="@+id/menuOrder"
            android:title="@string/order"/>
    
        <item
            android:id="@+id/menuPayments"
            android:icon="@drawable/ic_payment"
            android:title="@string/account_balance"/>
    
    
        <item android:title="@string/others">
    
            <menu>
    
                <item
                    android:id="@+id/menuSetting"
                    android:title="@string/setting"/>
    
                <item
                    android:id="@+id/menuSupport"
    
                    android:title="@string/support"/>
    
                <item
                    android:id="@+id/menuLogout"
                    android:title="@string/logout"/>
            </menu>
    
        </item>
    
    </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">
    
        <RoundedImageView
            android:id="@+id/imageProfile"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:scaleType="centerCrop"
            android:src="@drawable/splash2"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    
        <View
            android:id="@+id/viewSupporter"
            android:layout_width="1dp"
            android:layout_height="1dp"
            app:layout_constraintBottom_toBottomOf="@id/imageProfile"
            app:layout_constraintEnd_toEndOf="@id/imageProfile"
            app:layout_constraintStart_toStartOf="@id/imageProfile"
            app:layout_constraintTop_toTopOf="@+id/imageProfile" />
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:hint="Username"
            android:textColor="@color/bPrimary"
            android:textSize="18sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toTopOf="@id/viewSupporter"
            app:layout_constraintStart_toEndOf="@id/imageProfile"
            android:id="@+id/username"/>
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:text="@string/verified"
            android:textColor="@color/bGreen"
            android:textSize="16sp"
            app:layout_constraintStart_toEndOf="@id/imageProfile"
            app:layout_constraintTop_toBottomOf="@id/viewSupporter" />
    
        <View
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:background="@color/bGreen"
            android:foregroundGravity="bottom"
            android:paddingBottom="10dp"
            app:layout_constraintTop_toBottomOf="@id/imageProfile" />
    
    </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

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
    implementation 'com.google.firebase:firebase-auth:19.4.0'
    implementation 'com.google.firebase:firebase-firestore:21.7.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

   
    implementation 'com.android.support:multidex:1.0.3'

    //Navigation Component
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.1'

    // Material Design
    implementation 'com.google.android.material:material:1.3.0-alpha03'

       // Rounded Image View
    implementation 'com.makeramen:roundedimageview:2.3.0'

}

引起:java.lang.ClassNotFoundException:沒有找到類“android.view.ConstraintLayout”

問題出在您的layout/layout_navigation_header

androidx.constraintlayout.widget.ConstraintLayout

代替

ConstraintLayout

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM