13

After taking a look at the new methods in Material Design, I tried to implement a Floating Action Button in an app. However, I am getting this error in my preview (Previewing Android version 21):

The following classes could not be instantiated:
- android.support.design.widget.FloatingActionButton
(First paragraph of error)
java.lang.NullPointerException
at android.support.v4.graphics.drawable.DrawableCompatLollipop.setTintList(DrawableCompatLollipop.java:56)
at android.support.v4.graphics.drawable.DrawableCompat$LollipopDrawableImpl.setTintList(DrawableCompat.java:145)
at android.support.v4.graphics.drawable.DrawableCompat.setTintList(DrawableCompat.java:270)
etc...

Anyone have any idea? This is my build.gradle:

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
classpath 'com.android.tools.build:gradle:1.2.3'


defaultConfig {
    applicationId "owensetiawan.tutorials.fab"
    minSdkVersion 15
    targetSdkVersion 22
    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:design:22.2.0'
}

It would be absolutely fantastic if someone could help me shed some light on my problem.

planetastro
  • 1,716
  • 2
  • 15
  • 28
  • Many people have reported having issues with the new FAB button (widget) - I would suggest you use one of the popular libraries meanwhile (I did this) until the FAB button bugs are fixed – Eenvincible Jul 09 '15 at 13:39
  • @Eenvincible Really? Oh well, then I hope Google fixes this soon. Meanwhile, any good libraries you can recommend? – planetastro Jul 09 '15 at 13:48
  • I used this in my recently published app : https://github.com/makovkastar/FloatingActionButton – Eenvincible Jul 09 '15 at 16:02
  • I am getting the same error in the preview pane but it compiles without any error and even works on the device. This is definitely a bug and needs to be fixed. – sahil shekhawat Jul 09 '15 at 19:58
  • These issues are explained very well here : http://antonioleiva.com/floating-action-button/ – sahil shekhawat Jul 09 '15 at 20:05

4 Answers4

5

Hey i got the same problem with the instantiated of design library and solved it by this

Step 1 > code for fab

    <android.support.design.widget.FloatingActionButton
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"
      android:clickable="true"
      android:src="@drawable/search"
      app:backgroundTint="@color/color_fav"
      app:borderWidth="0dp"
      android:layout_alignParentBottom="true"
      android:layout_alignParentEnd="true"
      />

step 2 > dependency

    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile "com.android.support:support-v4:22.2.1"

step 3 > the main step for above problem

easy one:- go to your xml and click on preview and in the bar in preview select AP1 21

Nike15
  • 544
  • 3
  • 16
Sachin
  • 176
  • 1
  • 11
4

Make sure that the VERSION for AppCompat Library and the Design Support Library is the same. This is mostly an internal dependency conflict, keeping both versions same fixed it for me :-

compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
Prateek Prasad
  • 827
  • 2
  • 10
  • 19
1

I had the same issue updated "Android Support Library"(22.2.1). Read my answer for same type of issue. Cannot setup floating action buttons as class cannot be found (Android Studio)

Community
  • 1
  • 1
Niroshan
  • 1,174
  • 1
  • 12
  • 30
0

I had a similar error, simply change the Manifest from:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="victor.com.ec.gastos_diarios">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".ActividadPrincipal">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

to

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="victor.com.ec.gastos_diarios">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity 
            android:name=".ActividadPrincipal"
            android:theme="@style/AppTheme.NoActionBar">>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Bö macht Blau
  • 12,820
  • 5
  • 40
  • 61