How to fix the DrawerLayout inflation error in Android

If you are trying to use the DrawerLayout in your Android app(perhaps from the example project?), and your app is crashing when you try to run it, and you are getting a lot of errors saying

Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v4.widget.DrawerLayout

or something like:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.navigationdrawerexample/com.example.android.navigationdrawerexample.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v4.widget.DrawerLayout

...

Caused by: java.lang.ClassNotFoundException: android.support.v4.widget.DrawerLayout  

Here is how to fix the problem

I was having this problem myself, and I stumbled upon the solution here, at stackoverflow, posted by Daniel Lerps.

The problem may be that some build path libraries have been unchecked, after updating the Android Developer Tools.

  1. Right click your project, go to Build Path -> Configure Build Path
  2. Go to the Order and export tab
  3. Check the libraries. And hit Ok
    build-path

  4. Then go to Project in the main menu, and Clean your project, to rebuild it and try and run it again.

Also, make sure you have added the Android v4 support library to your project, and that you have updated ADT and Eclipse to the latest.

To add the support library to your project, just right-click the project -> Android Tools -> Add support library

These steps solved the problem for me atleast.

comments powered by Disqus