错误二进制XML文件行#31:在最新版本的Android Studio中输入类info.hoang8f.widget.FButton时出错

时间:2017-11-02 14:43:47

标签: android android-studio

我是android studio的新手。我使用Fbutton pakage来设计按钮。当我更新android studio时,我的应用程序停止了。我检查了logcat并看到了以下错误。

11-02 17:16:56.170 3195-3195/com.example.zfarzaneh.fitnessyoga E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.example.zfarzaneh.fitnessyoga, PID: 3195
                                                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.zfarzaneh.fitnessyoga/com.example.zfarzaneh.fitnessyoga.MainActivity}: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class info.hoang8f.widget.FButton
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                              Caused by: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class info.hoang8f.widget.FButton
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                                                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                                 at com.example.zfarzaneh.fitnessyoga.MainActivity.onCreate(MainActivity.java:14)
                                                                                 at android.app.Activity.performCreate(Activity.java:6237)
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:148) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                              Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class info.hoang8f.widget.FButton
                                                                                 at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                                                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                 at com.example.zfarzaneh.fitnessyoga.MainActivity.onCreate(MainActivity.java:14) 
                                                                                 at android.app.Activity.performCreate(Activity.java:6237) 
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:148) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                              Caused by: java.lang.reflect.InvocationTargetException
                                                                                 at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                                 at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                                                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                 at com.example.zfarzaneh.fitnessyoga.MainActivity.onCreate(MainActivity.java:14) 
                                                                                 at android.app.Activity.performCreate(Activity.java:6237) 
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:148) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                              Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x5
                                                                                 at android.content.res.TypedArray.getColor(TypedArray.java:451)
                                                                                 at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
                                                                                 at info.hoang8f.widget.FButton.<init>(FButton.java:52)
                                                                                 at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                                                 at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                                                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                 at com.example.zfarzaneh.fitnessyoga.MainActivity.onCreate(MainActivity.java:14) 
                                                                                 at android.app.Activity.performCreate(Activity.java:6237) 
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:148) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

所以我谷歌搜索并找到this question。但是当我更改gradle版本时,我得到了以下错误。所以我将设置设置为第一个。

Error:(22, 0) Could not find method implementation() for arguments [directory 'libs'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. <a href="openFile:C:\Users\zfarzaneh\AndroidStudioProjects\yogafitness4\app\build.gradle">Open File</a>

Befor更新的视觉工作室我使用了持续版本的gradle我对Fbutton pakage没有任何问题。我该如何解决?

修改 正如@TokajiP悲伤我改变了实现,编译如下:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'

compile 'com.android.support:cardview-v7:26.1.0'
compile 'info.hoang8f:fbutton:1.0.5'
// compile 'com.iangclifton.android:floatlabel:1.0.4'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testcompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:1.0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}

但我低于错误。

Error:(30, 0) Could not get unknown property 'compile' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.<a href="openFile:C:\Users\zfarzaneh\AndroidStudioProjects\fitnessYoga3\app\build.gradle">Open File</a>

为什么呢?怎么修复它?

2 个答案:

答案 0 :(得分:0)

将Gradle插件设置为2.3.3时,您将没有implementation依赖关系添加关键字。
您需要将应用implementation文件中的compile更改为build.gradle

在这里,您可以找到有关从2.3.3迁移到3.0.0的更多详细信息: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

答案 1 :(得分:0)

这将是最简单的解决方法。你根本不需要整个图书馆。这是一个单独的java类。所以你可以这样做。

只需复制名为

的java类
  

FButton.java

  

的src /主/爪哇/

https://github.com/hoang8f/android-flat-button/tree/master/library/src/main/java/info/hoang8f/widget

只需复制

中的值

https://github.com/hoang8f/android-flat-button/tree/master/library/src/main/res/values

res/values/attrs.xml
res/values/colors.xml
res/values/dimens.xml

并与attrs.xml,colors.xml and dimens.xml合并。如果这些文件夹不存在,只需复制它们即可。注意:请不要更换它们。在执行所有这些步骤后也删除此compile 'info.hoang8f:fbutton:1.0.5,您必须从xml中删除info.hoang8f.widget.FButton并将其替换为您复制的新Fbutton。