Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android.Views.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView

I am using a material navigation drawer in my android project using Xamarin. I have been trying to add two Framelayouts into the drawerlayout so that I can switch the content from different fragments see below xml:

 <?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"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
      <!-- This LinearLayout represents the contents of the screen  -->
      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">
        <!-- The ActionBar displayed at the top -->
        <include
            layout="@layout/toolbar"
android:id="@+id/toolbar" />
        <!-- The main content view where fragments are loaded -->
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:id="@+id/scrollview">
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">
            <FrameLayout
                android:id="@+id/search_frame"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@+id/blah"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
          </LinearLayout>
        </ScrollView>
      </LinearLayout>
      <!-- The navigation drawer that comes from the left -->
      <!-- Note that `android:layout_gravity` needs to be set to 'start' -->
      <android.support.design.widget.NavigationView
          android:id="@+id/nav_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          app:menu="@menu/drawer_view"
          app:itemTextColor="#FFFFFF"
          app:itemIconTint="#FFFFFF"
          android:background="#464646"/>
    </android.support.v4.widget.DrawerLayout>

The main activity :

protected override void OnCreate(Android_OS.Bundle bundle)
{
    base.OnCreate(bundle);

    SetContentView(Resource.Layout.activity_main);

    drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
    // Setting up the toolbar
    var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
    SetSupportActionBar(toolbar);
    SupportActionBar.SetTitle(Resource.String.ApplicationName);
    SupportActionBar.SetDisplayHomeAsUpEnabled(true);
    SupportActionBar.SetDisplayShowHomeEnabled(true);

    // Attach item selected handler to navigation view
    var navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
    navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;

    // Create ActionBarDrawerToggle button and add it to the toolbar
    var drawerToggle = new Android_Support.V7.App.ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.open_drawer, Resource.String.close_drawer);
    drawerLayout.SetDrawerListener(drawerToggle);
    drawerToggle.SyncState();
}

I get the following error: Android.Views.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView

I have tried moving the elements in the Drawerlayout but the error is persistent. I have looked at the Android documentation everything seems correct. I have also checked that I have the most recent version of both the Design and AppCompact library

like image 537
George Avatar asked Mar 09 '16 09:03

George


2 Answers

I was facing the same problem some time back, I don't know exactly what caused it, but I can tell you what I did, maybe it can help you.

  1. My phone memory was almost full, so I deleted some apps
  2. I uninstalled the app which was giving the error
  3. I cleaned and rebuilt the project
  4. Ran it again.

Voila! It worked.

like image 92
Harshit Kumar Avatar answered Sep 23 '22 10:09

Harshit Kumar


I may be late, but i just got the same error. So on AndroidStudio, i just cleaned my project ("Clean Projet"). After that i was able to run my project once again without that error.

like image 27
aristide.t.m Avatar answered Sep 19 '22 10:09

aristide.t.m