1

I am having an issue with a RuntimeException and InflateException stating Binary XML file: Error inflating class android.support.v7.widget.Toolbar. I created a project which attempts to use a navigation drawer and created an android-support-v7-appcompat library (following the directions through google docs) using Android 5.0. In the app, I am extending a NavigationDrawerActivity. I am not sure what is causing this. The libraries seem to be set up correctly, but the app crashes upon launch.

MainActivity.java

public class MainActivity extends NavigationDrawerActivity {

    private static final String LOGTAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        // Layout
        setContentView(R.layout.activity_main);

        super.onCreate(savedInstanceState);

NavigationDrawerActivity.java

public class NavigationDrawerActivity extends ActionBarActivity 
{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Use ToolBar and set it as ActionBar
        Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
        setSupportActionBar(toolbar);

activity_main.xml

<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"
    android:fitsSystemWindows="true"     xmlns:app="http://schemas.android.com/apk/res/com.mobile_iab_ad_framework">

<!--     Added fitSystemWindows to allow NavDrawer overlay ActionBar -->

<!--     To display fragments -->
    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

<!--         Use a Toolbar so the drawer can be displayed over ActionBar -->
        <android.support.v7.widget.Toolbar
            android:id="@+id/my_awesome_toolbar"
            style="@style/HeaderBar"
            app:theme="@style/ActionBarThemeOverlay"
            app:popupTheme="@style/ActionBarPopupThemeOverlay"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </FrameLayout>

<!--        Listview to display slider menu -->
        <ListView
            android:id="@+id/list_slidermenu"
            android:layout_width="240dp"
            android:layout_height="match_parent" 
            android:layout_gravity="start"
            android:background="@color/list_background"
            android:choiceMode="singleChoice"
            android:divider="@color/list_divider"
            android:dividerHeight="0dp"
            android:listSelector="@drawable/list_selector" />
</android.support.v4.widget.DrawerLayout>

LogCat Log

12-06 03:06:56.487: E/AndroidRuntime(7105): FATAL EXCEPTION: main
12-06 03:06:56.487: E/AndroidRuntime(7105): Process: com.package, PID: 7105
12-06 03:06:56.487: E/AndroidRuntime(7105): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobile_iab_ad_framework/com.package.device_discovery.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.v7.widget.Toolbar
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.app.ActivityThread.access$900(ActivityThread.java:161)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.os.Handler.dispatchMessage(Handler.java:102)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.os.Looper.loop(Looper.java:157)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.app.ActivityThread.main(ActivityThread.java:5356)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at java.lang.reflect.Method.invokeNative(Native Method)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at java.lang.reflect.Method.invoke(Method.java:515)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at dalvik.system.NativeStart.main(Native Method)
12-06 03:06:56.487: E/AndroidRuntime(7105): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.v7.widget.Toolbar
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.view.LayoutInflater.createView(LayoutInflater.java:626)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at com.package.device_discovery.MainActivity.onCreate(MainActivity.java:51)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.app.Activity.performCreate(Activity.java:5431)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
12-06 03:06:56.487: E/AndroidRuntime(7105):     ... 11 more
12-06 03:06:56.487: E/AndroidRuntime(7105): Caused by: java.lang.reflect.InvocationTargetException
12-06 03:06:56.487: E/AndroidRuntime(7105):     at java.lang.reflect.Constructor.constructNative(Native Method)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.view.LayoutInflater.createView(LayoutInflater.java:600)
12-06 03:06:56.487: E/AndroidRuntime(7105):     ... 23 more
12-06 03:06:56.487: E/AndroidRuntime(7105): Caused by: java.lang.NoSuchMethodError: android.support.v4.content.ContextCompat.getDrawable
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.support.v7.internal.widget.TintManager.getDrawable(TintManager.java:133)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.support.v7.internal.widget.TintTypedArray.getDrawable(TintTypedArray.java:62)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.support.v7.widget.Toolbar.<init>(Toolbar.java:249)
12-06 03:06:56.487: E/AndroidRuntime(7105):     at android.support.v7.widget.Toolbar.<init>(Toolbar.java:191)
12-06 03:06:56.487: E/AndroidRuntime(7105):     ... 26 more

styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="windowActionBar">false</item>
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="windowActionBar">false</item>
    </style>

    <!--  Extends Theme.Holo.Light and removes the Action Bar -->
    <style name="ThemeWithoutActionBar" parent="android:Theme.Holo.Light">
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
    </style>

    <!-- ************************************************************** -->
    <!-- Action Bar Style (Requires API 11) -->
    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@color/action_bar_bg</item>
        <item name="android:height">60dp</item>
        <item name="android:titleTextStyle">@style/MyActionBar.TitleTextStyle</item>
    </style>
    <!-- ************************************************************** -->

    <!-- ************************************************************** -->
    <!-- Action Bar Text Style (Requires API 13) -->
    <style name="MyActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">#FFFFFF</item>
        <item name="android:textSize">20sp</item>
    </style>
    <!-- ************************************************************** -->



    <!-- ************************************************************** -->
    <!-- Toolbar Style -->
    <style name="toolbarStyle" parent="Theme.AppCompat">

    </style>

    <style name="ActionBarThemeOverlay" parent="">
        <!-- Color of Toolbar Font Color -->
        <item name="android:textColorPrimary">@android:color/white</item>

        <!-- Color of Toolbar Action Buttons -->
        <item name="colorControlNormal">@android:color/black</item>
        <item name="colorControlHighlight">@android:color/black</item>
    </style>

    <style name="HeaderBar">
        <!-- Color of Toolbar Background Color -->
        <item name="android:background">@color/action_bar_bg</item>
        <item name="android:minHeight">80dp</item>
    </style>

    <style name="ActionBarPopupThemeOverlay" parent="ThemeOverlay.AppCompat.Light" >
        <!-- Color of Toolbar Popup from Action Overflow -->
        <!-- 
        <item name="android:background">@android:color/holo_green_light</item>
        <item name="android:textColor">@android:color/holo_green_dark</item>
        -->
    </style>
    <!-- ************************************************************** -->

</resources>
code
  • 5,294
  • 16
  • 62
  • 113
  • 1
    It feels like perhaps you are using an older version of the `support-v4` library. `getDrawable()` on `ContextCompat` was added sometime in the past year or so. – CommonsWare Dec 06 '14 at 21:18
  • Hi commonsWare. You make a good point. I'm also using android-support-v13.jar library file and I noticed in the console, it's printing this message: "WARNING: Found both android-support-v4 and android-support-v13 in the dependency list. Because v13 includes v4, using only v13." – code Dec 06 '14 at 21:26
  • 1
    Either `support-v13` or `support-v4` will provide the `ContextCompat` class. So, now it sounds like perhaps you are using an older version of `support-v13`. – CommonsWare Dec 06 '14 at 21:29
  • Thank you CommonsWare. So i tried removing support-v13 but it looks like I need it for FragmentPagerAdapter and FragmentStatePagerAdapter. Does support-v4 contain these classes? If not, i think you are right, I'll need support-v13 but a newer version of it – code Dec 06 '14 at 21:33
  • 1
    If you are using native API Level 11+ fragments, you need the `support-v13` edition of the `Fragment*PagerAdapter` classes. If you are using the backport of fragments, you need the `support-v4` edition of the `Fragment*PagerAdapter` classes. – CommonsWare Dec 06 '14 at 21:34

1 Answers1

1

The solution was to use the latest versions of the android-support-v4, android-support-v13, android-support-v7 libraries.

code
  • 5,294
  • 16
  • 62
  • 113