2015-07-09 10 views
10

Nachdem ich mir die neuen Methoden in Material Design angesehen habe, habe ich versucht, eine Floating Action-Schaltfläche in einer App zu implementieren. Allerdings erhalte ich diesen Fehler in meiner Vorschau (Vorschau Android-Version 21):FloatingActionButton-Klasse konnte nicht instanziiert werden

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... 

Wer noch keine Idee? Das ist mein 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' 
} 

Es wäre absolut fantastisch, wenn jemand könnte mir ein Licht auf meinem Problem helfen, Schuppen.

+0

Viele Leute haben berichtet, Probleme mit der neuen FAB-Taste (Widget) - ich würde vorschlagen, Sie verwenden eine der populären Bibliotheken inzwischen (ich tat dies), bis die FAB-Taste Fehler behoben sind – Eenvincible

+0

@Eenvincible Rea ly? Na gut, dann hoffe ich Google das bald zu beheben. In der Zwischenzeit können Sie irgendwelche guten Bibliotheken empfehlen? –

+0

Ich habe dies in meiner kürzlich veröffentlichten App verwendet: https://github.com/makovkastar/FloatingActionButton – Eenvincible

Antwort

5

Hey habe ich das gleiche Problem mit dem Design-Bibliothek instanziiert und löste es durch diese

Schritt 1> Code für 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" 
     /> 

Schritt 2> Abhängigkeit

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" 

Schritt 3> der Hauptschritt für das obige Problem

einfach: - gehen Sie zu Ihrem xml und klicken Sie auf Vorschau und in der Bar in der Vorschau AP1 wählen 21

+0

Sie haben meinen Tag gerettet, danke! – linqu

4

Vergewissern Sie sich, dass die VERSION für AppCompat Bibliothek und die Design Support-Bibliothek die gleiche ist . Dies ist vor allem eine interne Abhängigkeit Konflikt, beide Versionen zu halten gleiche es für mich festgelegt: -

compile 'com.android.support:appcompat-v7:24.2.1' 
compile 'com.android.support:design:24.2.1' 
1

ich einen ähnlichen Fehler hatte, einfach die von Manifest ändern:

<?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> 

zu

<?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> 
Verwandte Themen