0

PLease any good android developer help me resolve this issue

issue happening here :

android:background="@drawable/splash_bg"

splash_bg is vector image

and my sdk target is 28 if i remove this (android:background="@drawable/splash_bg") then code pass by this and then any other activity have background defined and it gives error:

I tried:

1) check all xml images are in drawable not in *-v24

2) size of splash_bg

but nothing seems work resolve this issue

PLEASE PLEASE Help me to resolve this issue, I will very thankfull.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:background="@drawable/splash_bg"

    android:id="@+id/vSplash"

    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_margin="60dp"
        android:layout_alignParentStart="true">

<!--        <ImageView
            android:id="@+id/ivbelowLogo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="30dp"
            android:layout_marginStart="30dp"
            android:layout_marginEnd="30dp"
            android:layout_weight="0"
            android:layout_alignParentTop="true"
            android:adjustViewBounds="true"
            android:src="@drawable/splash_zayed_big" />-->

        <ImageView android:id="@+id/ivSplash"
            android:layout_width="match_parent"
            android:layout_weight="4"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/splash_logo"
            android:layout_gravity="center"/>

        <ImageView android:id="@+id/ivSplashGif"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/splash_loading"
            android:layout_gravity="center"/>


    </LinearLayout>


    <RelativeLayout
        android:id="@+id/versionLayout"
        android:layout_width="wrap_content"
        android:layoutDirection="ltr"
        android:layout_marginBottom="10dp"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_height="wrap_content">

        <TextView android:id="@+id/tvVersion"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:textColor="@color/white"
            android:textSize="12dp"
            android:text="@string/version_name"/>

        <!--<TextView android:id="@+id/tvPowered"-->
            <!--android:layout_below="@id/tvVersion"-->
            <!--android:textSize="12dp"-->
            <!--android:layout_centerVertical="true"-->
            <!--android:layout_width="wrap_content"-->
            <!--android:layout_height="wrap_content"-->
            <!--android:text="@string/beta_version" />-->

    </RelativeLayout>

</RelativeLayout>

Working fine on all devices except few it is crashing.

This is the issue:

android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout

E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{ae.abc.xyzapp/ae.abc.xyzapp.ui.InitActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
        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:5001)
        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:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
        at android.view.LayoutInflater.createView(LayoutInflater.java:620)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at android.app.Activity.performCreate(Activity.java:5231)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
        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:5001) 
        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:785) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
        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 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
        at ae.mazadat.onlineauctionapp.ui.InitActivity.onCreate(InitActivity.java:87) 
        at android.app.Activity.performCreate(Activity.java:5231) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
        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:5001) 
        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:785) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_bg.xml from drawable resource ID #0x7f080216
        at android.content.res.Resources.loadDrawable(Resources.java:2096)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
        at android.view.View.<init>(View.java:3554)
        at android.view.View.<init>(View.java:3484)
        at android.view.ViewGroup.<init>(ViewGroup.java:464)
        at android.widget.RelativeLayout.<init>(RelativeLayout.java:236)
        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 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
        at ae.mazadat.onlineauctionapp.ui.InitActivity.onCreate(InitActivity.java:87) 
        at android.app.Activity.performCreate(Activity.java:5231) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
        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:5001) 
        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:785) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag vector
        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
        at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
        at android.content.res.Resources.loadDrawable(Resources.java:2092)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:602) 
        at android.view.View.<init>(View.java:3554) 
        at android.view.View.<init>(View.java:3484) 
        at android.view.ViewGroup.<init>(ViewGroup.java:464) 
        at android.widget.RelativeLayout.<init>(RelativeLayout.java:236) 
        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 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
        at ae.mazadat.onlineauctionapp.ui.InitActivity.onCreate(InitActivity.java:87) 
        at android.app.Activity.performCreate(Activity.java:5231) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
        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:5001) 
        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:785) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
        at dalvik.system.NativeStart.main(Native Method)
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

3 Answers3

0

That will only work if the device is running Android >= 5.X.X. Support for vector drawables was introduced there.

There are some compatibility options for ImageView on the AndroidX library, but I am not sure you can do anything for the background attribute on layouts. Just add a .png in your drawable-hdpi, drawable-xhdpi, etc, etc, to support API levels below 21.

Reaper
  • 486
  • 3
  • 12
0

Make sure, you have added your SVG resources with Android import, as described in the official doc.

enter image description here

GensaGames
  • 5,538
  • 4
  • 24
  • 53
0

You can handle this situation by an other way. It seems to be good for somehow.

Add an ImageView in your RelativeLayout and put your splash_bg img there in ImageView rather than RelativeLayout. By going this way your app will not crash and you will get the solution.

Update your XML like below:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@drawable/splash_bg" <!--remove from here -->
    android:id="@+id/vSplash"
    android:layout_height="match_parent">

<!-- put your splash here -->
    <ImageView  
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/splash_bg"/>


 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        ...

</RelativeLayout>

Hope this will help!!

Irfan Akram
  • 718
  • 1
  • 11
  • 20
  • can u tell me by doing it android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/splash_bg"/> It will leave spaces from left and right? How to resolve that cause i did and its leaving left and right spaces – Faisal Liaquat Nov 11 '19 at 18:45
  • @FaisalLiaquat - Probably, It depends on the image you're using. Use `android:fitsSystemWindows="true"` or `android:scaleType="fitXY"` in your ImgView. It will fit your image to the whole screen if there will be any space in any axis. Thanks! – Irfan Akram Nov 11 '19 at 18:50
  • Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score. i marked it alreadt but one more quesiton like on layout wise its working but what about when i try to do like R.drawable.menu_icons_my_account – Faisal Liaquat Nov 11 '19 at 19:41
  • but what about when i try to do like R.drawable.menu_icons_my_account it is not getting the image – Faisal Liaquat Nov 11 '19 at 19:43
  • @FaisalLiaquat - From which folder/directory you wanna get image? – Irfan Akram Nov 11 '19 at 19:50
  • R.drawable.new_logo when i am doing ivLogo.setImageDrawable(getResources().getDrawable(R.drawable.new_logo)); it is crashing cause same issue new_logo cannot find ... i am runnning android version less than 5.0.0 – Faisal Liaquat Nov 11 '19 at 19:53
  • Put the code like this `ivLogo.setImageResource(R.drawable.new_logo);` This may help! – Irfan Akram Nov 11 '19 at 20:04
  • @IrfanAkram Did you try my answer? – GensaGames Nov 12 '19 at 02:04
  • i want to try it @GensaGames but the problem is if its even worked then i dont have all the svgs properly. As all the files are in XML, if you hvae idea can u tell me if i can convert XML to SVG , no online tool used – Faisal Liaquat Nov 12 '19 at 07:06