Error inflating class android.support.v4.widget.drawerlayout
Asked Answered
N

8

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>
Nilsanilsen answered 25/2, 2014 at 17:15 Comment(0)
S
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

Saltpeter answered 13/4, 2019 at 4:15 Comment(0)
S
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.

Swivet answered 27/7, 2019 at 0:11 Comment(1)
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 XGertudegerty
N
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.

Nilsanilsen answered 25/2, 2014 at 22:0 Comment(3)
I'm hoping the same happens to me...only time will tell :'(Uptodate
Lols...!! Exactly sometimes this is tricky with android development ;-) Just restart eclipse / restart PC. :DEpigene
I've read the first answer and migrated to androidx and it solved the problem for me. But after reading this, I doubt that migration was required. Do you still use android.support?Shaquitashara
S
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.

Skylight answered 7/4, 2014 at 14:40 Comment(1)
I changed the order of v4 and v7 support library. Now it works.Daph
T
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'

Tole answered 13/6, 2015 at 9:43 Comment(1)
Adding the latest support library fixed the issue for meGriffen
R
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

Radiance answered 11/3, 2019 at 11:53 Comment(0)
G
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.

Gulp answered 19/6, 2019 at 17:56 Comment(0)
E
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...

Envision answered 11/10, 2014 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.