15

After I updated my project to AndroidX with targetSdkVersion set to 28, my project crashes when installing it from the store for beta testing.

The following is the error log I receive:

2019-07-08 08:28:33.026 32011-32011/? E/AndroidRuntime: FATAL EXCEPTION: main Process: hu.itq.oakprotection, PID: 32011
        java.lang.RuntimeException: Unable to start activity ComponentInfo{hu.itq.oakprotection/hu.itq.oakprotection.MainActivity}: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.google.android.material.navigation.NavigationView
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
            at android.app.ActivityThread.-wrap12(Unknown Source:0)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
            at android.os.Handler.dispatchMessage(Handler.java:108)
            at android.os.Looper.loop(Looper.java:166)
            at android.app.ActivityThread.main(ActivityThread.java:7425)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
         Caused by: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.google.android.material.navigation.NavigationView
         Caused by: android.view.InflateException: Binary XML file line #15: 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:658)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
            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.c(Unknown Source:23)
            at androidx.appcompat.app.AppCompatActivity.setContentView(Unknown Source:4)
            at hu.itq.oakprotection.MainActivity.onCreate(Unknown Source:6)
            at android.app.Activity.performCreate(Activity.java:7372)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
            at android.app.ActivityThread.-wrap12(Unknown Source:0)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
            at android.os.Handler.dispatchMessage(Handler.java:108)
            at android.os.Looper.loop(Looper.java:166)
            at android.app.ActivityThread.main(ActivityThread.java:7425)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
         Caused by: java.lang.NoSuchMethodError: No interface method d()I in class Lorg/xmlpull/v1/XmlPullParser; or its super classes (declaration of 'org.xmlpull.v1.XmlPullParser' appears in /system/framework/core-libart.jar)
            at androidx.appcompat.view.SupportMenuInflater.a(Unknown Source:5)
            at androidx.appcompat.view.SupportMenuInflater.inflate(Unknown Source:25)
            at com.google.android.material.navigation.NavigationView.b(Unknown Source:12)
            at com.google.android.material.navigation.NavigationView.<init>(Unknown Source:255)
            at com.google.android.material.navigation.NavigationView.<init>(Unknown Source:2)
            at java.lang.reflect.Constructor.newInstance0(Native Method) 
            at java.lang.reflect.Constructor.newInstance(Constructor.java:334) 

The following are my dependencies in build.gradle file:

android {
    compileSdkVersion 28
    def versionMajor = 1
    def versionMinor = 0
    def versionPatch = 1
    def versionBuild = 4 // ezt kell átírni új verzió kirakásakor

    defaultConfig {
        applicationId "hu.itq.oakprotection"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation 'androidx.core:core:1.0.2'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.annotation:annotation:1.1.0'

    implementation 'com.payumoney.sdkui:plug-n-play:1.2.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.android.material:material:1.1.0-alpha07'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'com.google.android.gms:play-services-base:17.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    //Test error miatt kellett
    implementation 'androidx.annotation:annotation:1.1.0'

    //Aszinkron hálózatokhoz
    implementation 'com.android.volley:volley:1.1.1'

    //Facebook
    implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
    //Osm Droid
    implementation 'org.osmdroid:osmdroid-android:6.1.0'
    implementation 'com.github.MKergall:osmbonuspack:6.4'

    implementation 'com.github.angads25:filepicker:1.1.1'
    //Tile provider igényli
    implementation 'mil.nga.geopackage:geopackage-android:3.0.2'
    implementation 'com.j256.ormlite:ormlite-android:5.1'
    implementation 'mil.nga.geopackage:geopackage-core:3.0.2'
    implementation 'ar.com.hjg:pngj:2.1.0'
    implementation 'mil.nga:tiff:2.0.0'
    implementation('mil.nga.geopackage:geopackage-android:3.0.2') {
        exclude group: 'com.google.android.gms', module: 'play-services'
        exclude group: 'com.google.maps.android', module: 'android-maps-utils'
        exclude group: 'com.android.support', module: 'support-v13'
    }
    //Glide
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
    //Mapsforge rendering and database support, which is LGPL
    implementation 'org.mapsforge:mapsforge-map-android:0.8.0'
    implementation 'org.mapsforge:mapsforge-map:0.8.0'
    implementation 'org.mapsforge:mapsforge-themes:0.8.0'
    // ExoPlayer
    implementation 'com.google.android.exoplayer:exoplayer:2.7.3'
    //Youtube
    implementation 'com.github.HaarigerHarald:android-youtubeExtractor:v1.7.0'}

activity_main.xml:

<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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
    tools:context=".MainActivity">

    <include
        layout="@layout/app_bar_main" />

    <com.google.android.material.navigation.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"
        app:itemIconTint="@color/colorPrimary"
        app:itemTextColor="@color/colorPrimary"
        android:backgroundTint="@color/colorWhite"/>

</androidx.drawerlayout.widget.DrawerLayout>

Why am I receiving an android.view.InflateException error for NavigationView?

live-love
  • 48,840
  • 22
  • 240
  • 204
Tankos
  • 181
  • 1
  • 1
  • 8

14 Answers14

18

There are multiple reasons why this error can occur. Check the following and make sure they are proper:

  • Check your code for drawable and color resources used inside the com.google.android.material.navigation.NavigationView you've used, probably in activity_main.xml, if you're using the default Navigation Drawer template code from Android Studio.
  • Check that the drawable files are in res/drawable folder, not in res/drawable-v21.
  • Check if you've used android:backgroundTint() or android:src or similar inside your NavigationView. Since they don't work below android API Level 21, use app:backgroundTint or app:srcCompat instead.
SaadAAkash
  • 3,065
  • 3
  • 19
  • 25
  • 1
    The problem was: android: backgroundTint = "@ color / colorWhite". Solution: app: backgroundTint = "@ color / colorWhite" Thank you, you saved my day ;) – Tankos Jul 08 '19 at 11:54
  • Glad I could help you! These are the 3 usual suspects that I always look for when encountered with this error. – SaadAAkash Jul 08 '19 at 11:56
  • i have same issue 1) I am not using backgrounTint or android:src 2) I am not using color or drawable in NavigationView but my application crash on this line setContentView(R.layout.layout_base_activity); – Muhammad Tufail Oct 08 '19 at 13:33
  • @MuhammadTufail, then it must have been something else which is the cause of the crash. What's the error log saying? Did you ask any separate question, I can't seem to find it on your profile. – SaadAAkash Oct 08 '19 at 14:16
  • Thanks for the reply no i didn't ask any separate question. My error is same android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.google.android.material.navigation.NavigationView All androidx dependencies are added i recheck my code 5-6 time. I also remove all the drawable and colour for testing but app crash again.. – Muhammad Tufail Oct 09 '19 at 05:51
  • @MuhammadTufail Then please ask a new question & post your entire code on your `NavigationView`, error log and check you've implemented/migrated to AndroidX correctly. – SaadAAkash Oct 09 '19 at 06:20
  • If i ask new question then developer will say duplicate question. – Muhammad Tufail Oct 09 '19 at 06:24
  • @MuhammadTufail post the links in the 1st paragraph to mention your research efforts, put codes and express that you've not found a solution – SaadAAkash Oct 09 '19 at 06:26
  • 1
    You're welcome @MD.Riyaz. Glad my answer solved your problem as well. Do consider giving an upvote since it helped. – SaadAAkash Jan 08 '20 at 19:40
  • this answer saved my day – Yash M. Hanj Jun 19 '20 at 10:21
  • 1
    Happy to help @YashM.Hanj – SaadAAkash Jun 19 '20 at 13:50
  • This helped me track down my issue. The errors made me look somewhere else but this one help me get back on track. Thank you – kuchi Jul 21 '20 at 09:18
5

For those who the chosen answer didn't help them, I've found that had a problem with NavigationView theme and it should be an appCompat theme (at least for me). after creating a new style like:

<style name="NavView" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    ...
</style>

and used it with android:theme="@style/NavView" in NavigationView in my mainactivity.xml, the app runs perfectly now.

Burzum
  • 170
  • 2
  • 15
4

In my case, the issue is in navigation.NavigationView app:headerLayout layout I am setting

<ImageView 
  app:srcCompat="@mipmap/ic_launcher_round"
/> 

and the problem is with ic_launcher_round because this is inside folder mipmap-anydpi-v26 and I am using android version 7.1.1 that is API Level: 25

hope this helps anyone

Zeeshan Akhtar
  • 441
  • 1
  • 4
  • 9
3

In my case the problem was the theme value in the Manifest file

<activity
        android:name=".ui.BarcodeReaderDrawerActivity"
        android:label="@string/title_activity_barcode_reader_drawer">
        android:theme="@style/AppBaseTheme.NoActionBar"
    </activity>

Changed in

<activity
        android:name=".ui.BarcodeReaderDrawerActivity"
        android:label="@string/title_activity_barcode_reader_drawer"
        android:theme="@style/Theme.MaterialComponents.Light.NoActionBar">
    </activity>
1

You can check your XML file. Something wrong in your xml like menu, nav header and other. In my Case, wrong in res/menu/menu.xml

Izzamed
  • 83
  • 4
1

I had this error during upgrade to Androidx, it was hard to find. The problem was with the activity theme.

In styles.xml, somehow I had the wrong android material theme, and it was causing the navigation bar not be attached to the action bar.

from:

    <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">

to:

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
live-love
  • 48,840
  • 22
  • 240
  • 204
1

I tried changing module settings, gradle settings, changing dependencies and many thing and found the issue is with the navigation view, But a different kind of issue i.e.

The image choosen for drawer layout is overflowed -> so just change the image or edit it resize it and then try.

So because of that the Navigation View throws error in some devices.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Anand Jha
  • 17
  • 3
1

This error is related to the theme. I solved my problem by commenting the following line from the theme

  <style name="AppTheme.NavigationView"  >
    <!--<item name="android:textColorSecondary">#FFFFFF</item>-->
    <item name="android:scrollbarThumbVertical">@android:color/transparent</item>
    <item name="elevation">0dp</item>
</style>

By removing or commenting line by line on the theme code, you can quickly conclude where the problem is.

Mostafa Rostami
  • 1,906
  • 20
  • 29
1

In my case, this helps. Hope this answer helps someone facing an issue

 <style name="Theme.PLCDrive" parent="Theme.MaterialComponents.Light.NoActionBar">

in my case when the theme style was MaterialComponents it keeps crashing and as I changed to AppCompat error resolved and works

<style name="Theme.PLCDrive" parent="Theme.AppCompat.Light.NoActionBar">
Zahid Iqbal
  • 394
  • 6
  • 12
0

android.view.InflateException: means there is something wrong in your XML file itself.

Please check all your dimensions, color resources, and other resources you have assigned in the XML tag.

Or post your XML file here.

UserSharma
  • 458
  • 6
  • 20
0

In my case, I manually moved everything in res/drawable-v24 to res/drawable folder and res/mipmap-anydpi-v26 to res/mipmap-hdpi and problem was solved in phones with Android 5 and 6.

0

My issue was not because of android:src

but because I was using a vector gradient as the background( android:background="@drawable/bg") inside nav header layout

and it was only happening in Android 6

I changed the vector from this:

<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt" android:width="200dp" android:height="133dp" android:viewportWidth="375" android:viewportHeight="280">
    <path android:pathData="M0 0h375v280H0V0z">
        <aapt:attr name="android:fillColor">
            <gradient android:endX="497.417" android:endY="263.205" android:startX="150.5" android:startY="-33.5" android:type="linear">
                <item android:color="#FFFFFFFF" android:offset="0"/>
                <item android:color="#00000000" android:offset="1"/>
            </gradient>
        </aapt:attr>
    </path>
</vector>

to this

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

    <gradient
        android:angle="315"
        android:endColor="#ffffff"
        android:startColor="#000000"
        android:type="linear" />
</shape>

and the crash disapperard

hushed_voice
  • 3,161
  • 3
  • 34
  • 66
0

Got the same issue. In my case I have put my navigation drawer menu icon inside drawable-v24 folder. This should be placed inside drawable folder. Once I moved the icons from drawable-v24 folder to drawable folder it works fine. Hopefully this will be helpful

Shadat
  • 150
  • 2
  • 4
-1

In my case, in the navigation header layout, I had an image that was too big and was not fitting in the screen. I changed that icon and it ran.