Binary XML file line # 16: Error inflating class android.support.design.widget.NavigationView

0

Good morning.

I just finished developing an app, and I've been testing it all the time on the same device, the Samsung glaxy S6. In the samung everything is correct, without any problem ... I have tried it on another motorcycle and it is also great. What has been my surprise that when loading it in a Sony Xperia v or in a Xiaomi Note with a couple of years, it does not stop, and this error comes out:

2.controlbt E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.oftecnica2.controlbt/com.example.oftecnica2.controlbt.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2383)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2435)
    at android.app.ActivityThread.access$600(ActivityThread.java:168)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5435)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:857)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
    at android.view.LayoutInflater.createView(LayoutInflater.java:683)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:816)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:559)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:419)
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at com.example.oftecnica2.controlbt.MainActivity.onCreate(MainActivity.java:49)
    at android.app.Activity.performCreate(Activity.java:5224)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1151)
    at com.lbe.security.service.core.client.internal.InstrumentationDelegate.callActivityOnCreate(InstrumentationDelegate.java:76)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2347)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2435) 
    at android.app.ActivityThread.access$600(ActivityThread.java:168) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:194) 
    at android.app.ActivityThread.main(ActivityThread.java:5435) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:525) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:857) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 
    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:417)
    at android.view.LayoutInflater.createView(LayoutInflater.java:657)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:816) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:559) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:419) 
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
    at com.example.oftecnica2.controlbt.MainActivity.onCreate(MainActivity.java:49) 
    at android.app.Activity.performCreate(Activity.java:5224) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1151) 
    at com.lbe.security.service.core.client.internal.InstrumentationDelegate.callActivityOnCreate(InstrumentationDelegate.java:76) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2347) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2435) 
    at android.app.ActivityThread.access$600(ActivityThread.java:168) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:194) 
    at android.app.ActivityThread.main(ActivityThread.java:5435) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:525) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:857) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 
    at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class ImageView
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:816)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:559)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
    at android.support.design.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:189)
    at android.support.design.widget.NavigationView.inflateHeaderView(NavigationView.java:262)
    at android.support.design.widget.NavigationView.<init>(NavigationView.java:173)
    at android.support.design.widget.NavigationView.<init>(NavigationView.java:95)
    at java.lang.reflect.Constructor.constructNative(Native Method) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:657) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:816) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:559) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:419) 
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
    at com.example.oftecnica2.controlbt.MainActivity.onCreate(MainActivity.java:49) 
    at android.app.Activity.performCreate(Activity.java:5224) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1151) 
    at com.lbe.security.service.core.client.internal.InstrumentationDelegate.callActivityOnCreate(InstrumentationDelegate.java:76) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2347) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2435) 
    at android.app.ActivityThread.access$600(ActivityThread.java:168) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:194) 
    at android.app.ActivityThread.main(ActivityThread.java:5435) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:525) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:857) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 
    at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f02005d a=-1 r=0x7f02005d}
    at android.content.res.Resources.loadDrawable(Resources.java:2006)
    at android.content.res.MiuiResources.loadDrawable(MiuiResources.java:317)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
    at android.widget.ImageView.<init>(ImageView.java:120)
    at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
    at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
    at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
    at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
    at android.support.v7.app.AppCompa
    07-22 11:05:14.240 18143-18143/com.example.oftecnica2.controlbt I/Process: Sending signal. PID: 18143 SIG: 9

I attached my main, which is the activity that gives error:

MAIN:

layout:

    <?xml version="1.0" encoding="utf-8"?>
<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_main"
        app:menu="@menu/activity_main_drawer"/>

</android.support.v4.widget.DrawerLayout>

and the manifest:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
<uses-permission android:name="android.permission.VIBRATE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".Splash"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Seleccion"
        android:screenOrientation="portrait"/>
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme.NoActionBar"
        android:screenOrientation="portrait"/>
</application>

Gradle:

apply plugin: 'com.android.application'

android {     compileSdkVersion 23     buildToolsVersion "22"

defaultConfig {
    applicationId "com.example.oftecnica2.controlbt"
    minSdkVersion 17
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
}

what can it be?

    
asked by Sergio Cv 22.07.2016 в 12:21
source

4 answers

2

If the icons that you are using in the menu are vectors then the problem may be that this type of graphics only works with versions 21 or higher, for compatibility with previous versions you have to add the classic png images for the different ones Resolutions (mdpi, hdpi, xhdpi, xxhdpi)

    
answered by 29.11.2017 в 17:55
1

These are the errors that your LogCat shows:

  

Caused by: android.view.InflateException: Binary XML file line # 14:   Inflating class ImageView error

     

Caused by: android.view.InflateException: Binary XML file line # 16:   Error inflating class android.support.design.widget.NavigationView

     

Caused by: android.content.res.Resources $ NotFoundException: Resource   is not to Drawable (color or path): TypedValue {t = 0x1 / d = 0x7f02005d a = -1   r = 0x7f02005d}

It can be determined that the problem is within a layout and you have a reference to a drawable which is not really a Drawable , in this kind of cases the problem is not seen in the main layout, the problem is probably within the layout that loads your include, app_bar_main.xml or the header of NavigationView that is nav_header_main.xml

<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_main"
        app:menu="@menu/activity_main_drawer"/>
    
answered by 25.07.2016 в 20:25
0

I suppose it is because of the versions of the APIs that some dependencies may not support, try to add any of these dependencies:

 compile "com.android.support:appcompat-v7:21.0.3"
 compile 'com.android.support:appcompat-v7:23.1.1'
 compile 'com.android.support:design:23.1.1'
    
answered by 25.07.2016 в 16:44
-1

Go to your project in Android Studio and open the build.gradle file at the module level.

Situate in block dependencies and check that your support and design libraries match in the same version.

For example ...

The project that I'm running now has them like this:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    // más...
} 

Obviously the version you choose should be according to the compilation version and the target .

    compileSdkVersion 24
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "<paquete>"
        minSdkVersion 13
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }

Run the app and see if that was it.

If it turns out that this was the problem, you can avoid it in the future by using a variable in the build.gradle file at project level.

Unblock and create a block named ext and include a variable called supportLibraryVersion . Assign the value of the support library:

ext {
    // Otras...

    // Dependencias
    supportLibraryVersion = '24.1.1'
}

Now return to the file level module and make the reference to the variable:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.ext.supportLibraryVersion"
}

With this you only update the variable so that the dependencies are on par at any time.

Another factor

Notice that the dependency of the Drawable element that you are told about is not produced by any element of your styles.xml file that is only used in versions greater than 21.

For example, do not use the main style:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

Instead of name="android:colorPrimary" .

It also checks the layouts to see if there is a component that tries to use attributes that are only for certain versions of Android.

You will know it if you see that Lint annotations are lit in red or yellow.

Greetings!

    
answered by 27.07.2016 в 03:16