Android KitKat: android.view.InflateException: Error inflating class android.support.design.widget.NavigationView

后端 未结 4 1560
日久生厌
日久生厌 2020-12-17 04:08

Below is my configuration. This works on Android Lollipop but crash on Android Kitkat.

I tried every workaround here but can\'t help:
Error inflating class and

相关标签:
4条回答
  • I found it. The error comes from navigation's menu. When I created new project with navigation drawer, Android Studio generates complete work for me. There's a drawable folder named drawable-v21 which stores the icon xml files like this:

    ic_menu_send.xml

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportHeight="24.0"
        android:viewportWidth="24.0">
        <path
            android:fillColor="#FF000000"
            android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z" />
    </vector>  
    

    And it's my bad. I missed to put ic_menu_send.png for pre-lollipop version.

    0 讨论(0)
  • 2020-12-17 04:29

    Option 1: Make sure that the file names matches- "@mipmap/icon.png" nd "@mipmap/icon.xml"

    Option 2: In the degub window u will see the Resource id as : r-0X000fd something.... go to the R file nd check for this resource due to which the error is generated....

    To do so : C:\Users\akshyata\Desktop\FoodSanta_Folders\FoodSanta\app\build\generated\source\r\debug\'your_package_name'\R.java

    Open the R file in notepad nd do "CTRL+F" nd type the resource id. You will find the resource which generated the error...GO nd solve the error

    Happy Coding

    0 讨论(0)
  • 2020-12-17 04:38

    I used Activity Gallery in Android studio to create navigation drawer activity

    then I noticed that the template added images in a way that version 21 and above can understand, these images for menu items in navigation view

    and here is the error

    Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020052
    ......
    ......
    android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems
    

    and if you traced the Resource ID #0x7f020052 in R file

    you will find it belong to that image which android did no Recognize(find) it because it recognizable by android v21 not 19 or lower

    so add png images for pre-lollipop android devices

    0 讨论(0)
  • 2020-12-17 04:38

    I have the similar issue. after spending many days and testing finally found the issue. this might be comes from one of your menu item icon or from a navigation header.

    have checked the navigationview by removing

    app:headerLayout="@layout/nav_header_main"
    
    app:menu="@menu/activity_main_drawer
    

    these two line separately and check the android monitor for errors

    <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer"
    />
    

    check my thread and answer. hope you can fix it from that Error Inflate with resourcenotfoundException

    0 讨论(0)
提交回复
热议问题