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 android.support.design.widget.NavigationView
build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
// Support RenderScript Library v8
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
}
}
ext{
supportLibVersion = '23.1.1'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
}
Theme style.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Layout activity_main.xml
<android.support.v4.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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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_logged_out_kp"
app:itemTextColor="@color/textColorPrimary"
app:menu="@menu/activity_drawer" />
</android.support.v4.widget.DrawerLayout>
Activity oncreate()
setSupportActionBar(toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);
navHeaderView = navigationView.getHeaderView(0);
Menu activity_drawer.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_kpv"
android:icon="@drawable/ic_menu_person"
android:title="@string/action_kpv" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="@+id/nav_send"
android:icon="@drawable/ic_menu_send"
android:title="Send" />
</menu>
</item>
</menu>
Here is the error I get:
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:627)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:703)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.cammob.watershed.kp.ui.KPMainActivity.onCreate(KPMainActivity.java:68)
at android.app.Activity.performCreate(Activity.java:5447)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:601)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:703)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.cammob.watershed.kp.ui.KPMainActivity.onCreate(KPMainActivity.java:68)
at android.app.Activity.performCreate(Activity.java:5447)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
Update: NavigationView's header nav_header_logged_out_kp.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
>
<!--android:background="@drawable/side_nav_bar"-->
<ImageView
android:id="@+id/imageBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<Button
android:id="@+id/buttonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/login"/>
</FrameLayout>
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.
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
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
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
来源:https://stackoverflow.com/questions/35472963/android-kitkat-android-view-inflateexception-error-inflating-class-android-sup