9

I have some problems with the DrawerLayout component. I'm using the android-support-v4 jar and when I'm launching the app I have this exception :

05-19 01:33:57.402: E/AndroidRuntime(3120): FATAL EXCEPTION: main
05-19 01:33:57.402: E/AndroidRuntime(3120): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dimosphere.app/com.dimosphere.app.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v4.widget.DrawerLayout
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.app.ActivityThread.access$600(ActivityThread.java:153)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.os.Looper.loop(Looper.java:137)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.app.ActivityThread.main(ActivityThread.java:5226)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at java.lang.reflect.Method.invokeNative(Native Method)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at java.lang.reflect.Method.invoke(Method.java:511)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at dalvik.system.NativeStart.main(Native Method)
05-19 01:33:57.402: E/AndroidRuntime(3120): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v4.widget.DrawerLayout
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:323)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.app.Activity.setContentView(Activity.java:1881)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at com.dimosphere.app.MainActivity.onCreate(MainActivity.java:12)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.app.Activity.performCreate(Activity.java:5104)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
05-19 01:33:57.402: E/AndroidRuntime(3120):     ... 11 more
05-19 01:33:57.402: E/AndroidRuntime(3120): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.widget.DrawerLayout" on path: /data/app/com.dimosphere.app-2.apk
05-19 01:33:57.402: E/AndroidRuntime(3120):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.view.LayoutInflater.createView(LayoutInflater.java:552)
05-19 01:33:57.402: E/AndroidRuntime(3120):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
05-19 01:33:57.402: E/AndroidRuntime(3120):     ... 20 more

I don't understand why do I have this exception, I included the jar in project properties...

Here is my xml file :

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

    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>

</android.support.v4.widget.DrawerLayout>

If you have any idea about where is the problem, you're welcome... Thanks :)

Ahmad Kayyali
  • 8,233
  • 13
  • 49
  • 83
Kyu_
  • 800
  • 4
  • 10
  • 18

2 Answers2

10

Add android-support-v4 to your build path

mromer
  • 1,867
  • 1
  • 13
  • 18
  • @user1563059 So, what exactly was it? – cringe May 21 '13 at 18:08
  • 1
    I'm pretty sure he used an outdated version of the support library. – Greeny May 22 '13 at 07:30
  • 9
    In "Order and export", I had not checked the box before "android-support-v4" -_- – Kyu_ May 22 '13 at 07:44
  • 1
    DrawerLayout was added in support lib v13, but +1 for the checkbox in order and export. – Erik B Jul 08 '13 at 22:19
  • Had the same issue, the problem was an outdated version of the support library. However, just updating it didnt fix the issue, not even after cleaning project and reopening eclipse. I had to manually remove "Android Dependencies", and then add the support library again (click on project, and go "Add support library"). – bgse Aug 22 '13 at 23:00
0

I had the same problem with using Android Studio. I had a number of build dependencies, among them the support-v4 library. Everything worked well until I integrated the DrawerLayout - that's where the above error occurred.

I resolved it by simply removing the support-v4 library from the dependencies. It was already included by another dependency (in my case the Facebook SDK), and it seems that this was causing the trouble (maybe due to different versions). Maybe this helps someone in a similar position :)

akohout
  • 1,802
  • 3
  • 23
  • 42