Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error inflating class android.support.v4.widget.drawerlayout

I've done numerous searches on this topic. I have done the following:

  1. Made sure the support library was up to date via the SDK Manager.
  2. Went into the build path and the order and export tab to make sure dependencies were checked.
  3. Cleaned my project and restarted adt.
  4. right clicked the project -> android tools -> add support library.

I have used the support library for another project and it works fine but I wasn't using the drawerlayout. Below is the xml file I am calling within my activity class. This error happens when it calls setContentView(R.layout.main_sliding_layout);

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"       
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>
like image 849
user3241191 Avatar asked Feb 25 '14 17:02

user3241191


4 Answers

In the latest releases:
If you are using androidx support library then,

Use:
androidx.drawerlayout.widget.DrawerLayout

Instead of:
android.support.v4.widget.DrawerLayout

and

Use:
com.google.android.material.navigation.NavigationView

Instead of:
android.support.design.widget.NavigationView

For other equivalent androidx classes please refer below link: https://developer.android.com/jetpack/androidx/migrate

like image 174
Kalpesh Wadekar Avatar answered Oct 05 '22 00:10

Kalpesh Wadekar


If you just migrated to AndroidX, a same error would pop up.

Error inflating class androidx.core.widget.DrawerLayout

Just change

androidx.core.widget.DrawerLayout

to

androidx.drawerlayout.widget.DrawerLayout

in every XML.

like image 39
Hamza Hathoute Avatar answered Oct 05 '22 00:10

Hamza Hathoute


If anyone is looking for a resolution or what happened with this, it will remain a mystery. I walked away for a couple hours to just relax and clear my head thinking I'd come back and pin point what I was over looking. I started the application and the thing just started working. I didn't make any new updates or anything. Fantastic that it is working but doesn't really help as to what was going on. Oh well, onward and upward.

like image 42
user3241191 Avatar answered Oct 04 '22 22:10

user3241191


Follow steps:

1.Configure Build-Path

2.Add Android library,and android dependencies libraries

3.Order and Export all those dependencies and android library.

like image 23
Chinmay Pingale Avatar answered Oct 04 '22 22:10

Chinmay Pingale