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

99封情书 提交于 2019-12-10 02:47:08

问题


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>

回答1:


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




回答2:


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.




回答3:


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.




回答4:


Follow steps:

1.Configure Build-Path

2.Add Android library,and android dependencies libraries

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




回答5:


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'




回答6:


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




回答7:


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...




回答8:


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.



来源:https://stackoverflow.com/questions/22021416/error-inflating-class-android-support-v4-widget-drawerlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!