17

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>
user3241191
  • 505
  • 2
  • 5
  • 12

8 Answers8

27

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

Kalpesh Wadekar
  • 1,237
  • 11
  • 19
19

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.

Hamza Hathoute
  • 438
  • 3
  • 12
  • thank you very much for saving a lot of time for me:-) It works now! just changed this in all xml files in android studio with shortcut Ctrl+Shift+R on Windows and Linux/Ubuntu Cmd+Shift+R on Mac OS X – phil Oct 30 '19 at 20:16
7

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.

user3241191
  • 505
  • 2
  • 5
  • 12
3

Follow steps:

1.Configure Build-Path

2.Add Android library,and android dependencies libraries

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

3

Go to build.gradle script and add a dependancy to support

by adding this in dependancies compile 'com.android.support:support-v4:22.1.1'

Om Komawar
  • 251
  • 3
  • 19
3

I got this error when I created a new project with the new AndroidX and copied codes from my last project which was using support Library, inside this one.

Solved it by replacing android.support.v4.widget.DrawerLayout with androidx.drawerlayout.widget.DrawerLayout

3

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 this link: Thanks a lot.

Mohammad Sommakia
  • 1,773
  • 3
  • 15
  • 48
1

Many times there is no error but still it shows error inflating class android.support.v4.widget.drawerlayout.

I solved my problem by adding Android Support Library

Steps

Right click on Project-> Android Tools->Add Support library.

then I just cleaned the project and I worked for me...

And Obviously Check the Android Library and other Libarary...

Arhat Baid
  • 1,011
  • 10
  • 18