Error inflating class Android support design

13,440

Solution 1

If you are using any of the Design Library components, you should ensure your activity extends AppCompatActivity and uses an appropriate Theme.AppCompat theme. Note that the FloatingActionButton relies on the colorAccent set on your theme - ensure your theme has that defined.

Solution 2

This error can be caused due to reasons as mentioned below.

  1. This problem will likely occur when the version of your appcompat library and design support library doesn't match.

Example of matching condition

  compile 'com.android.support:appcompat-v7:24.2.0' // appcompat library

  compile 'com.android.support:design:24.2.0' //design support library
  1. Your theme file in styles should not have

    <item name="colorPrimary">#4A0958</item>
    <item name="colorPrimaryDark">#4A0958</item>
    

    It should look somewhat like this.

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    
     <item name="colorPrimary">#4A0958</item>
     <item name="colorPrimaryDark">#4A0958</item>
     <item name="colorAccent">#4A0958</item>
    
    </style>
    

Solution 3

If everything else doesn't work, Upgrade the version of the dependency and version. In your build.gradle file:

compileSdkVersion 24

compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
Share:
13,440

Related videos on Youtube

ez4nick
Author by

ez4nick

Updated on September 14, 2022

Comments

  • ez4nick
    ez4nick almost 2 years

    What I am trying to do is use the new android support design library mentioned here: http://android-developers.blogspot.com/2015/05/android-design-support-library.html.

    I have attempted to use the floating action button as follows in my xml layout (this is where the below error is coming from):

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/adview"
        android:layout_marginTop="500dp" />
    

    When my app is launched this is the error:

    06-06 20:56:43.186    6405-6405/com.nick.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.nick.app, PID: 6405
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nick.app/com.nick.app.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.design.widget.FloatingActionButton
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5290)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
     Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.design.widget.FloatingActionButton
            at android.view.LayoutInflater.createView(LayoutInflater.java:633)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:401)
            at android.app.Activity.setContentView(Activity.java:2197)
            at com.nick.app.MainActivity.onCreate(MainActivity.java:94)
            at android.app.Activity.performCreate(Activity.java:6020)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
                at android.app.ActivityThread.access$800(ActivityThread.java:149)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:135)
                at android.app.ActivityThread.main(ActivityThread.java:5290)
                at java.lang.reflect.Method.invoke(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:372)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
    

    in my build.gradle file for the app module I have compile 'com.android.support:design:22.2.0' as required.Also, other relevant parts from the build.gradle file:

    compileSdkVersion 21
    buildToolsVersion "21.1.1"
    defaultConfig {
        ...
        minSdkVersion 16
        targetSdkVersion 21
        .....
    

    I should also note that when I go to project structure->dependencies and I try to add a library dependency I cannot find "com.android.support:design:22.2.0" when searching (I am not sure if this is required in addition to adding the dependency in build.gradle file).

    Finally, in my SDK manager I have confirmed "Android Support Repository" and "Android Support Library" are up to date at versions 15 and 22.2, respectively.

    Are there any suggestions for what else I might try?

    I have found this answer: https://stackoverflow.com/a/30557995/1489990 and tried the solution however it did not solve my issue.

  • Victor Zamanian
    Victor Zamanian almost 9 years
    My theme has colorAccent defined, it uses an "appropriate" Theme.AppCompat theme (whatever that means; I'm trying Theme.AppCompat and Theme.AppCompat.Light), and my activity extends AppCompatActivity. all I'm getting is: "You need to use a Theme.AppCompat theme (or descendant) with this activity." [sad face]
  • Pierre
    Pierre over 5 years
    If it has compiled before and then suddenly started to give this error, try cleaning your project and then rebuild