简体   繁体   English

浮动操作按钮导致错误并导致应用程序崩溃

[英]Floating Action Button causing error and crashing application

When using the floating action button, my Android application crashes and throws an error. 使用浮动操作按钮时,我的Android应用程序崩溃并抛出错误。 When I remove it, my application runs successfully, but I'd rather use the floating action button if I can. 当我删除它时,我的应用程序运行成功,但如果可以,我宁愿使用浮动操作按钮。

This is my complete error log: 这是我完整的错误日志:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.supriya.hithere/com.example.supriya.hithere.MainActivity}: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.FloatingActionButton
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
     at android.app.ActivityThread.access$800(ActivityThread.java:135)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:136)
     at android.app.ActivityThread.main(ActivityThread.java:5021)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:515)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
     at dalvik.system.NativeStart.main(Native Method)
  Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.FloatingActionButton
     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
     at com.example.supriya.hithere.MainActivity.onCreate(MainActivity.java:47)
     at android.app.Activity.performCreate(Activity.java:5231)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
     at android.app.ActivityThread.access$800(ActivityThread.java:135) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:136) 
     at android.app.ActivityThread.main(ActivityThread.java:5021) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643) 
     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:423)
     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
     at com.example.supriya.hithere.MainActivity.onCreate(MainActivity.java:47) 
     at android.app.Activity.performCreate(Activity.java:5231) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
     at android.app.ActivityThread.access$800(ActivityThread.java:135) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:136) 
     at android.app.ActivityThread.main(ActivityThread.java:5021) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643) 
     at dalvik.system.NativeStart.main(Native Method) 
  Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f02005f a=-1 r=0x7f02005f}
     at android.content.res.Resources.loadDrawable(Resources.java:2103)
     at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
     at android.widget.ImageView.<init>(ImageView.java:129)
     at android.widget.ImageButton.<init>(ImageButton.java:87)
     at android.support.design.widget.VisibilityAwareImageButton.<init>(VisibilityAwareImageButton.java:36)
     at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:114)
     at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:110)
     at java.lang.reflect.Constructor.constructNative(Native Method) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
     at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
     at com.example.supriya.hithere.MainActivity.onCreate(MainActivity.java:47) 
     at android.app.Activity.performCreate(Activity.java:5231) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
     at android.app.ActivityThread.access$800(ActivityThread.java:135) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:136) 
     at android.app.ActivityThread.main(ActivityThread.java:5021) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643) 
     at dalvik.system.NativeStart.main(Native Method)

在此输入图像描述 在此输入图像描述

Make sure you are using AppCompatActivity instead of Activity , and AppCompat theme. 确保您使用的是AppCompatActivity而不是Activity和AppCompat主题。

<style name="Base.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

If you are using any attributes like backgroundTint or borderWidth for the FAB, make sure you are using app namespace. 如果您对FAB使用任何属性(如backgroundTintborderWidth ,请确保使用的是app namespace。

app:backgroundTint="@color/accent_color"
app:borderWidth="0dp"

I was facing the same issue. 我面临同样的问题。 Check that the version of appcompat and design library are same in your build.gradle app. 检查build.gradle应用程序中appcompat和design库的版本是否相同。 Or atleast the version of design library is not older than that of appcompat. 或者至少设计库的版本不比appcompat的版本旧。

For example: 例如:

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

This one work for me Finally 这个对我有用

compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM