У меня надувается класс android.support.design.widget.BottomNavigationView Ошибка. есть идеи? - PullRequest
0 голосов
/ 05 ноября 2019

Я попытался просмотреть свои XML-файлы, а также проверить все мои зависимости. Но я пока не смог точно определить, что не так.

Это сборка Gradle.

Сводка ошибок приведена внизу.

СборкаGradle (приложение)

apply plugin: 'com.android.application'
android {
 compileSdkVersion 29
 buildToolsVersion "29.0.2"
 defaultConfig {
     applicationId "com.example.hasanat"
     minSdkVersion 21
     targetSdkVersion 29
     versionCode 1
     versionName "1.0"
     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.1.0'
 implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
 implementation 'androidx.recyclerview:recyclerview:1.0.0'
 \

 //material view for android
 implementation 'com.google.android.material:material:1.2.0-alpha01'
 //AndroidX
 implementation 'androidx.cardview:cardview:1.0.0'
 implementation 'androidx.legacy:legacy-support-v4:1.0.0'
 testImplementation 'junit:junit:4.12'
 androidTestImplementation 'androidx.test:runner:1.2.0'
 androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
 implementation 'androidx.navigation:navigation-fragment:2.1.0-alpha02'
 implementation 'androidx.navigation:navigation-ui:2.1.0-alpha02'
}

Основной файл активности для справки activity_main

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout 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:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

<!--   Adding a Navigation Host  -->
  <fragment
     android:id="@+id/nav_host"
     android:layout_weight="1"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:name="androidx.navigation.fragment.NavHostFragment"
     app:navGraph="@navigation/hasanav"
     app:defaultNavHost="true"/>

<!--  Bottom Navigation Bar  -->

  <android.support.design.widget.BottomNavigationView
     android:id="@+id/bottom_navigation"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     app:menu="@menu/bottomnav"
     app:itemBackground="@color/colorPrimary"
     app:itemIconTint="@android:color/white"
     app:itemTextColor="@android:color/white" />


 <androidx.recyclerview.widget.RecyclerView
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:id="@+id/CharityOrgs"
     android:scrollbars="vertical">

 </androidx.recyclerview.widget.RecyclerView>


 </LinearLayout>

Сводка ошибок

Process: com.example.hasanat, PID: 32190
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hasanat/com.example.hasanat.MainActivity}: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class android.support.design.widget.BottomNavigationView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6810)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
     Caused by: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class android.support.design.widget.BottomNavigationView
     Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class android.support.design.widget.BottomNavigationView
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.BottomNavigationView" on path: DexPathList[[zip file "/data/app/com.example.hasanat-bWDmwmjIn_JgyVV7mVt1hQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.hasanat-bWDmwmjIn_JgyVV7mVt1hQ==/lib/arm64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.view.LayoutInflater.createView(LayoutInflater.java:610)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.example.hasanat.MainActivity.onCreate(MainActivity.java:38)
        at android.app.Activity.performCreate(Activity.java:7224)
        at android.app.Activity.performCreate(Activity.java:7213)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at         android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6810)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

1 Ответ

0 голосов
/ 05 ноября 2019

Вы используете dependencies из androidx, поэтому вам нужно использовать com.google.android.material.bottomnavigation.BottomNavigationView

Используйте это

<com.google.android.material.bottomnavigation.BottomNavigationView 
     android:id="@+id/bottom_navigation"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     app:menu="@menu/bottomnav"
     app:itemBackground="@color/colorPrimary"
     app:itemIconTint="@android:color/white"
     app:itemTextColor="@android:color/white" />

Вместо этого

<android.support.design.widget.BottomNavigationView
     android:id="@+id/bottom_navigation"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     app:menu="@menu/bottomnav"
     app:itemBackground="@color/colorPrimary"
     app:itemIconTint="@android:color/white"
     app:itemTextColor="@android:color/white" />
...