java - android.view.InflateException : Binary XML file line #29: Error inflating class android. widget.Button

标签 java android inflate-exception

我收到很多此类错误

android.view.InflateException: Binary XML file line #29: Error inflating class android.widget.Button

据我所知,多个不同的布局资源可能会发生此类错误。
谁能解释一下为什么会出现这个错误?
我能做些什么来解决这个问题?

此错误出现在 Samsung Galaxy S3 mini Android 版本 4.2.2 上。在其他 Android 版本 5.1.1 和 6.0.1 的设备上,按钮和图像可以正确显示。

布局:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.android.locator.WelcomeActivity">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/buttonForward"
            android:clickable="true"
            android:onClick="ClickForward"
            android:background="@drawable/button_footer_forward_enabled"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Klicke &quot;>&quot; zur Konfiguration"
            android:id="@+id/textView2"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Willkommen"
            android:id="@+id/textView3"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            style="@android:style/TextAppearance.DeviceDefault.DialogWindowTitle" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button2"
            android:clickable="true"
            android:onClick="ClickCancel"
            android:background="@drawable/button_footer_cancel_enabled"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true" />

    </RelativeLayout>

堆栈跟踪:

11-10 14:13:41.156 13504-13504/com.example.android.locator W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x418c5930)
11-10 14:13:41.195 13504-13504/com.example.android.locator E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                android.view.InflateException: Binary XML file line #29: Error inflating class android.widget.Button
                                                                                    at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                                                                                    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                                                                                    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
                                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
                                                                                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
                                                                                    at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
                                                                                    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
                                                                                    at android.view.LayoutInflater.inflate(Native Method)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                                    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:360)
                                                                                    at android.app.Activity.setContentView(Activity.java:1932)
                                                                                    at com.example.android.locator.WelcomeActivity$1.onFinish(WelcomeActivity.java:31)
                                                                                    at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                    at android.os.Looper.loop(Looper.java:176)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5365)
                                                                                    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:1102)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
                                                                                    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
                                                                                    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:593)
                                                                                    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                                                                                    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666) 
                                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691) 
                                                                                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:495) 
                                                                                    at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method) 
                                                                                    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631) 
                                                                                    at android.view.LayoutInflater.inflate(Native Method) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                                    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:360) 
                                                                                    at android.app.Activity.setContentView(Activity.java:1932) 
                                                                                    at com.example.android.locator.WelcomeActivity$1.onFinish(WelcomeActivity.java:31) 
                                                                                    at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118) 
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                    at android.os.Looper.loop(Looper.java:176) 
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5365) 
                                                                                    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:1102) 
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
                                                                                    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132) 
                                                                                    at dalvik.system.NativeStart.main(Native Method) 
                                                                                 Caused by: android.content.res.Resources$NotFoundException: File res/drawable/button_footer_cancel_enabled.xml from drawable resource ID #0x7f02004c
                                                                                    at android.content.res.Resources.loadDrawable(Resources.java:2842)
                                                                                    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                                    at android.content.res.XResources$XTypedArray.getDrawable(XResources.java:965)
                                                                                    at android.view.View.<init>(View.java:3542)
                                                                                    at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
                                                                                    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
                                                                                    at android.view.View.<init>(Native Method)
                                                                                    at android.widget.TextView.<init>(TextView.java:843)
                                                                                    at android.widget.Button.<init>(Button.java:130)
                                                                                    at android.widget.Button.<init>(Button.java:126)
                                                                                    at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                                    at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
                                                                                    at android.view.LayoutInflater.createView(LayoutInflater.java:593) 
                                                                                    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                                                                                    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666) 
                                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691) 
                                                                                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:495) 
                                                                                    at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method) 
                                                                                    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631) 
                                                                                    at android.view.LayoutInflater.inflate(Native Method) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                                    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:360) 
                                                                                    at android.app.Activity.setContentView(Activity.java:1932) 
                                                                                    at com.example.android.locator.WelcomeActivity$1.onFinish(WelcomeActivity.java:31) 
                                                                                    at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118) 
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                    at android.os.Looper.loop(Looper.java:176) 
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5365) 
                                                                                    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:1102) 
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
                                                                                    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132) 
                                                                                    at dalvik.system.NativeStart.main(Native Method) 
                                                                                 Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
                                                                                    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:917)
                                                                                    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:858)
                                                                                    at android.content.res.Resources.loadDrawable(Resources.java:2839)
                                                                                    at android.content.res.TypedArray.getDrawable(TypedArray.java:602) 
                                                                                    at android.content.res.XResources$XTypedArray.getDrawable(XResources.java:965) 
                                                                                    at android.view.View.<init>(View.java:3542) 
                                                                                    at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method) 
                                                                                    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631) 
                                                                                    at android.view.View.<init>(Native Method) 
                                                                                    at android.widget.TextView.<init>(TextView.java:843) 
                                                                                    at android.widget.Button.<init>(Button.java:130) 
                                                                                    at android.widget.Button.<init>(Button.java:126) 
                                                                                    at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                                    at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
                                                                                    at android.view.LayoutInflater.createView(LayoutInflater.java:593) 
                                                                                    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 

前进按钮:

<vector android:height="24dp" android:viewportHeight="47.0"
    android:viewportWidth="60.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#333" android:pathData="m24.8,35c0.2,0 0.5,-0.1 0.6,-0.2l11.3,-11.2c0.2,-0.2 0.3,-0.4 0.3,-0.7 0,-0.3 -0.1,-0.5 -0.3,-0.7l-11.3,-11c-0.2,-0.1 -0.4,-0.2 -0.6,-0.2 0,0 0,0 -0.1,0 -0.3,0 -0.5,0.1 -0.7,0.3l-0.8,1c-0.3,0.4 -0.3,0.9 0.1,1.3l9.1,9.4 -9.1,9.5c-0.4,0.3 -0.4,0.9 -0.1,1.3l0.9,1c0.2,0.1 0.4,0.2 0.7,0.2z"/>
</vector>

取消按钮:

<vector android:height="24dp" android:viewportHeight="47.0"
    android:viewportWidth="60.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#333" android:pathData="m39.5,28.8l-5.5,-5.5 -0.3,-0.3 5.8,-5.8c1,-1 1,-2.7 0,-3.7 -1,-1 -2.7,-1 -3.7,0l-5.8,5.8 -5.8,-5.8c-1,-1 -2.7,-1 -3.7,0 -1,1 -1,2.7 0,3.7l5.8,5.8 -0.3,0.3 -5.5,5.5c-1,1 -1,2.7 0,3.7 1,1 2.7,1 3.7,0l5.5,-5.5 0.3,-0.3 0.3,0.3 5.5,5.5c1,1 2.7,1 3.7,0 1,-1.1 1,-2.7 0,-3.7z"/>
</vector>

欢迎 Activity :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.splash);
    new CountDownTimer(3000,1000){
        @Override
        public void onTick(long millisUntilFinished){}

        @Override
        public void onFinish(){
            //set the new Content of your activity
            WelcomeActivity.this.setContentView(R.layout.activity_welcome);
        }
    }.start();
    getWindow().getDecorView().setBackgroundColor(Color.parseColor("#FFFFFF"));

}

最佳答案

您需要修复

android:background="@drawable/button_footer_forward_enabled"

也许

android:background="@drawable/button_footer_cancel_enabled"
<小时/>

你的错误在堆栈跟踪中,只需阅读它

资源$NotFoundException:文件 res/drawable/button_footer_cancel_enabled.xml

您可以通过将 vector 绘图放在正确的文件夹中来修复它

XmlPullParserException:二进制 XML 文件第 1 行:无效的可绘制标记 vector

您可以通过弄清楚如何正确使用 vector 绘图来解决这个问题

<小时/>

最终,您似乎想要一个 ImageButton。您将使用 app:srcCompat 设置正确的可绘制对象,而不是背景属性

关于java - android.view.InflateException : Binary XML file line #29: Error inflating class android. widget.Button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40531881/

相关文章:

java - 按数组中字符串的长度快速排序

java - 有什么方法可以下载旧版本的 appcompat 库吗?

java - 是否有 Java 到 Flash 的编译器?

android - 平板电脑摄像头的/dev/video0 的 Android 等价物是什么?

android - 无法使用 null 启动服务 com.google.android.gms.analytics.AnalyticsService@3399b37

java - 保存某些内容并转到下一个屏幕时,应用程序崩溃并且不再打开

java - 为什么不支持 SpringMVC 请求方法 'GET'?

android - 这是纹理吗?

java - Android InflateException - 膨胀类 com.google.vr.sdk.base.GvrView 时出错

android - 错误膨胀类 ImageButton