Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error inflating class android.support.design.widget.CoordinatorLayout

I would like use a FloatingActionButton on my application, I read this : https://guides.codepath.com/android/Floating-Action-Buttons#google-s-official-support-library but when I run the Activity I have this error :

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xavier_laffargue.podcast/com.xavier_laffargue.podcast.ACT_Test}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout

XML File

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/lvToDoList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="24dp"
        android:src="@drawable/ic_action_refresh"
        app:layout_anchor="@id/lvToDoList"
        app:layout_anchorGravity="bottom|right|end" />

</android.support.design.widget.CoordinatorLayout>

Graddle

*apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.xavier_laffargue.podcast"
        minSdkVersion 21
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.android.support:design:22.2.0'

    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:support-v13:22.2.0'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'

}
like image 307
xav-stargate Avatar asked Jun 01 '15 10:06

xav-stargate


2 Answers

For those using AndroidX Dependency

Along with changing dependencies, XML must also be changed.

from

<android.support.design.widget.CoordinatorLayout 

to

<androidx.coordinatorlayout.widget.CoordinatorLayout
like image 181
Amir Dora. Avatar answered Nov 11 '22 04:11

Amir Dora.


Please change it into AppCompatActivity if you use Activity. Probably it becomes the error when it is Activity.

like image 41
Mizuki Sonoko Avatar answered Nov 11 '22 03:11

Mizuki Sonoko