-8

<?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:menu="@menu/activity_main_drawer"/>
</android.support.v4.widget.DrawerLayout>

The app crashes while compilation, the crash report are :

java.lang.RuntimeException Unable to start activity ComponentInfo, android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.widget.NavigationView

I was strucked, Please provide idea to fix it.

Thanks

kgandroid
  • 5,507
  • 5
  • 39
  • 69

1 Answers1

0

You must add support libraries to your project.

  1. v7 Support
  2. v4 Suport
  3. V13 Support
  4. Design support library

Edit - I have used following code snippet and it worked for me. i.e.

<include
    layout="@layout/app_bar_drawer_sample"
    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_drawer_sample"
    app:menu="@menu/activity_drawer_sample_drawer" />

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

And if it does not work out please create a new NavigationDrawer Activity. By following steps

Right Click on Activity Package > New > Activity> NavigationDrawer Activity. It will generate a proper code. And you can then work upon.

Ankit Gupta
  • 674
  • 1
  • 6
  • 17