使用FloatingActionButton扩充异常

时间:2016-11-21 04:11:15

标签: android floating-action-button inflate-exception

我在支持库中遇到FloatActionButton问题。当我在棒棒糖前运行应用程序时,我收到此错误。我使用的是android studio 2.2.2,这个错误在以前的版本中没见过。但我最近遇到了这个问题。

E/AndroidRuntime: FATAL EXCEPTION: main
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jomlex.jomlex/com.jomlex.jomlex.MainActivity}: android.view.InflateException: Binary XML file line #45: Error inflating class android.support.design.widget.FloatingActionButton
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                  at android.app.ActivityThread.access$600(ActivityThread.java:141)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                  at android.os.Handler.dispatchMessage(Handler.java:99)
                  at android.os.Looper.loop(Looper.java:137)
                  at android.app.ActivityThread.main(ActivityThread.java:5041)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:511)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                  at dalvik.system.NativeStart.main(Native Method)
               Caused by: android.view.InflateException: Binary XML file line #45: Error inflating class android.support.design.widget.FloatingActionButton
                  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
                  at com.jomlex.jomlex.MainActivity.onCreate(MainActivity.java:127)
                  at android.app.Activity.performCreate(Activity.java:5104)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
                  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
                  at android.os.Handler.dispatchMessage(Handler.java:99) 
                  at android.os.Looper.loop(Looper.java:137) 
                  at android.app.ActivityThread.main(ActivityThread.java:5041) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:511) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
                  at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
                  at java.lang.reflect.Constructor.constructNative(Native Method)
                  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:736) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
                  at com.jomlex.jomlex.MainActivity.onCreate(MainActivity.java:127) 
                  at android.app.Activity.performCreate(Activity.java:5104) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
                  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
                  at android.os.Handler.dispatchMessage(Handler.java:99) 
                  at android.os.Looper.loop(Looper.java:137) 
                  at android.app.ActivityThread.main(ActivityThread.java:5041) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:511) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
                  at dalvik.system.NativeStart.main(Native Method) 
               Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020076
                  at android.content.res.Resources.getValue(Resources.java:1014)
                  at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:330)
                  at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
                  at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
                  at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
                  at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:54)
                  at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:177)
                  at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:153)
                  at java.lang.reflect.Constructor.constructNative(Native Method) 
                  at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
                  at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:736) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
                  at com.jomlex.jomlex.MainActivity.onCreate(MainActivity.java:127) 
                  at android.app.Activity.performCreate(Activity.java:5104) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
                  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
                  at android.os.Handler.dispatchMessage(Handler.java:99) 
                  at android.os.Looper.loop(Looper.java:137) 
                  at android.app.ActivityThread.main(ActivityThread.java:5041) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:511) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
                  at dalvik.system.NativeStart.main(Native Method)  

布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.jomlex.jomlex.MainActivity">


<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />


    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabTextColor="@color/gray"
        app:tabSelectedTextColor="@color/white"
        android:layoutDirection="ltr"
        app:tabIndicatorColor="@color/colorAccent"
        app:tabGravity="fill"
        app:tabMode="fixed" />

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

<klogi.com.RtlViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@drawable/ic_notifications"
    android:tint="@color/white"
    app:backgroundTint="@color/colorPrimary"
    app:layout_behavior="com.jomlex.jomlex.utils.ScrollAwareFABBehavior" />

Style.xml:

<resources>

<style name="AppTheme" parent="Base.AppTheme">

</style>
<style name="Base.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
</resources>

Gradle设置:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
    applicationId "com.jomlex.jomlex"
    minSdkVersion 17
    targetSdkVersion 25
    versionCode 5
    versionName '1.4'
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-    core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1'
compile 'com.android.support:support-vector-drawable:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'klogi.com:rtlviewpager:1.0.0'
compile 'com.malinskiy:superrecyclerview:1.1.4'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.github.mancj:MaterialSearchBar:0.3.1'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1@aar'
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
compile 'com.google.firebase:firebase-crash:9.8.0'
testCompile 'junit:junit:4.12'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
}
apply plugin: 'com.google.gms.google-services'

编辑:

Java代码(未完成):

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    forceRTLIfSupported();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent i = new Intent(MainActivity.this, SendActivity.class);
            startActivity(i);
        }
    });
}
}

manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jomlex.jomlex">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="www.jomlex.com"
                android:pathPrefix="/user"
                android:scheme="https" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="jomlex.com"
                android:pathPrefix="/user"
                android:scheme="https" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".LoginActivity"
        android:label="@string/title_activity_login"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="adjustResize" />
    <activity
        android:name=".ui.ProfileActivity"
        android:label="@string/title_acitivity_profile"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".ui.SearchActivity"
        android:label="جستجو"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".ui.SendActivity"
        android:label="ارسال جملکس"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize" />
    <activity
        android:name=".ui.SingleActivity"
        android:screenOrientation="portrait" />
    <activity
        android:name=".ui.registration.RegisterActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize" />
    <activity
        android:name=".ui.registration.CheckSMSActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize" />

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_icon_jomlex" />
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/white" />

    <service android:name=".utils.MyFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
    <service android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <activity android:name=".ui.SettingActivity"></activity>
</application>

1 个答案:

答案 0 :(得分:0)

我找到了答案。我的矢量是drawable-anydpi,我把它移到drawable,一切顺利。我认为这是因为android图像导入器插件。