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

时间:2016-05-04 06:22:57

标签: java android

使用浮动操作按钮时,我的Android应用程序崩溃并抛出错误。当我删除它时,我的应用程序运行成功,但如果可以,我宁愿使用浮动操作按钮。

这是我的完整错误日志:

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)

enter image description here enter image description here

3 个答案:

答案 0 :(得分:12)

确保您使用.gallery-image img { width: 100%!important; max-width: none; transition: transform .4s; } 代替AppCompatActivity和AppCompat主题。

Activity

如果您对FAB使用<style name="Base.AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> backgroundTint等任何属性,请确保使用borderWidth命名空间。

app

答案 1 :(得分:0)

我遇到了同样的问题。检查build.gradle应用程序中appcompat和design库的版本是否相同。或者至少设计库的版本不比appcompat版本早。

例如:

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

答案 2 :(得分:0)

这对我来说最后工作

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