kformeck kformeck - 3 months ago 95
Android Question

InflateException thrown when setting id on a FloatingActionButton

I have a floating action button control added to my main activity:

<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginRight="@dimen/main_fab_margin"
android:layout_marginBottom="@dimen/main_fab_margin"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_main_fab"
app:fabSize="normal"
app:backgroundTint="@color/color_primary"
app:elevation="@dimen/main_fab_elevation"/>
</RelativeLayout>

<!-- Pull-out navigation drawer (a.k.a hamburger menu) -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/navigationmenu"
app:headerLayout="@layout/drawerheader" />

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


This throws an InflateException that looks like:

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


The floating action button is a child of a RelativeLayout which a child of a android.support.v4.widget.DrawerLayout.

Now the weird part, when I remove

android:id="@+id/main_fab"


from the above code, everything works perfectly.

I have no idea what could be causing this. I really need to set an id to the button so I can control the clicks in the code-behind.

Any ideas?

Update

Stack trace:

Unhandled Exception:

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

08-04 16:49:39.952 E/AndroidRuntime(16025): FATAL EXCEPTION: main
08-04 16:49:39.952 E/AndroidRuntime(16025): Process: RA16mobile.RA16mobile, PID: 16025
08-04 16:49:39.952 E/AndroidRuntime(16025): android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.design.internal.NavigationMenuPresenter$NormalViewHolder.<init>(NavigationMenuPresenter.java:278)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:379)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:328)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1211)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
08-04 16:49:39.952 E/AndroidRuntime(16025): at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.View.layout(View.java:16646)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewGroup.layout(ViewGroup.java:5440)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2183)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1943)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6060)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.Choreographer.doCallbacks(Choreographer.java:670)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.Choreographer.doFrame(Choreographer.java:606)
08-04 16:49:39.952 E/AndroidRuntime(16025): at android.view.Choreograp
08-04 16:49:40.000 I/Process (16025): Sending signal. PID: 16025 SIG: 9

Answer

Try to nuke your obj/bin folders, Restart your IDE, and do a clean deploy. (i.e. adb uninstall packagename). I've seen this issue quite frequently with regards to Error inflating class android.support.design.internal.NavigationMenuItemView and it seems to fix it.

I thought originally this was a Xamarin specific error until I've encountered it in Native Java as well. Basically following the same steps resolves the issues in both lands.

Comments