0

I am receiving many errors of this kind

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

I learn that such error may occur for several different layout resources.
Can anybody explain why this error occurs?
And what I can do to fix this problem?

This error appears on Samsung Galaxy S3 mini Android Version 4.2.2. On Other Devices with Android Version 5.1.1 and 6.0.1 the Buttons and Images are displayed correctly.

Layout:

    <?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>

Stack trace:

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) 

Forward Button:

<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>

Cancel Button:

<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>

WelcomeActivity:

@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"));

}
user7142083
  • 9
  • 1
  • 3

3 Answers3

1

You need to fix

android:background="@drawable/button_footer_forward_enabled"

And probably

android:background="@drawable/button_footer_cancel_enabled"

Your errors are in the stacktrace, just need to read it

Resources$NotFoundException: File res/drawable/button_footer_cancel_enabled.xml

You can fix it by placing the vector drawable in the right folder

XmlPullParserException: Binary XML file line #1: invalid drawable tag vector

You can fix that by figuring out how to correctly use vector drawables


Ultimately, seems like you want an ImageButton. And you would use app:srcCompat to set the correct drawable, not the background attribute

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • The error appears on Samsung Galaxy S3 mini Android Version 4.2.2. On Other Devices with Android Version 5.1.1 and 6.0.1 the Buttons and Images are displayed correctly. – user7142083 Nov 10 '16 at 17:55
  • Don't know what to tell you. Just reading the error message, these are the only solutions I know of. – OneCricketeer Nov 10 '16 at 18:16
  • if i use app:srcCompat the error is gone and the buttons are displayed, but the images are not. is there common way how to use vector images/SVGs compatible with Android 4.2.2? – user7142083 Nov 11 '16 at 09:48
  • The support library should allow you to do so. http://android-developers.blogspot.com/2016/02/android-support-library-232.html?m=1 and https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.xxosv19nf and http://stackoverflow.com/questions/26548354/vectordrawable-is-it-available-somehow-for-pre-lollipop-versions-of-android – OneCricketeer Nov 11 '16 at 12:50
0

This answer is pretty late but to whom face this issue may help,

I have encountered with this error ,find out problem was my image located in specific drawable folders (mine was in device compatibility) and general drawable folder did not contain this image resource

0

Check the location of your drawable. This is a common mistake. Your button_footer_forward_enabled might be located in drawable-v21 instead of the drawable folder. Just move it from any other folder to drawable folder and that should resolve your issue.

Jaswant Singh
  • 9,900
  • 8
  • 29
  • 50