简体   繁体   中英

Fatal Error When Creating Navigation Drawer: InflateException: Binary XML file line #1: Error inflating class DrawerLayout

I'm attempting to follow this guide to implementing an Android Navigation Drawer:

http://codetheory.in/android-navigation-drawer/

and I'm getting following error:

07-06 11:59:06.125: E/AndroidRuntime(1878): FATAL EXCEPTION: main
07-06 11:59:06.125: E/AndroidRuntime(1878): Process: com.example.app, PID: 1878
07-06 11:59:06.125: E/AndroidRuntime(1878): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.Home}: android.view.InflateException: Binary XML file line #1: Error inflating class DrawerLayout
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.os.Handler.dispatchMessage(Handler.java:102)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.os.Looper.loop(Looper.java:136)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.app.ActivityThread.main(ActivityThread.java:5001)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at java.lang.reflect.Method.invokeNative(Native Method)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at java.lang.reflect.Method.invoke(Method.java:515)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at dalvik.system.NativeStart.main(Native Method)
07-06 11:59:06.125: E/AndroidRuntime(1878): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class DrawerLayout
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.app.Activity.setContentView(Activity.java:1929)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at com.example.app.Home.onCreate(Home.java:125)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.app.Activity.performCreate(Activity.java:5231)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
07-06 11:59:06.125: E/AndroidRuntime(1878):     ... 11 more
07-06 11:59:06.125: E/AndroidRuntime(1878): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.DrawerLayout" on path: DexPathList[[zip file "/data/app/com.example.app-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.app-2, /system/lib]]
07-06 11:59:06.125: E/AndroidRuntime(1878):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
07-06 11:59:06.125: E/AndroidRuntime(1878):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
07-06 11:59:06.125: E/AndroidRuntime(1878):     ... 20 more

In my source line # 125 is:

setContentView(R.layout.ss_home);

the contents of R.layout.ss_home are:

<DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="00dp"
    android:layout_marginTop="0dp"
    android:orientation="vertical"
    android:id="@+id/RootView" >

    <RelativeLayout
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:id="@+id/drawerPane"
        android:layout_gravity="start">

...

If anyone can shed some light on why this might be happening / how to resolve it - it would be greatly appreciated.

I'm stumped at this point (the resource it says is missing - exists! [also - I have tried cleaning the project and restarting Eclipse])

On the XML change, <DrawerLayout to <android.support.v4.widget.DrawerLayout

and don't forget to integrate the support library

You might have been missed out some classes migration while migrating to androidx. Like for me I was using old support class instead of androidx class for this component

android:appComponentFactory="androidx.core.app.CoreComponentFactory".

Check other andoridx classes here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM