Jignesh Siddhpura
Jignesh Siddhpura

Reputation: 45

Caused by: android.view.InflateException: Binary XML file

After Updating to the gradle 3.1.4 and moving to buildToolsVersion "27.0.3"

I'm Facing this issues

android.view.InflateException: Binary XML file line #41: Binary XML file line #41: Error inflating class ImageView

Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class ImageView
Caused by: android.content.res.Resources$NotFoundException: Drawable com.demo.android:drawable/ic_demo with resource ID #0x7f080160
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_demo.xml from drawable resource ID #0x7f080160

I tried to replace android:src to app:srcCompat and added vectorDrawables.useSupportLibrary = true in defaultConfig

Below is the layout file code

<RelativeLayout
     android:layout_width="wrap_content"
     android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/demo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:srcCompat="@drawable/ic_demo"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"
                    android:visibility="gone" />
</RelativeLayout>

UPDATE: I found an issue. issue is some of the vector are working and some of them are not supported though they are created in SVG format from same sources. Can anyone suggest me to convert the PNG to SVG FILE.

Upvotes: 1

Views: 3936

Answers (3)

karan
karan

Reputation: 8853

if your image is a vector drawable make sure you have done below code.

In your app's build.gradle add:

android {
    defaultConfig {
        vectorDrawables.useSupportLibrary = true
    }
}

And for vector support for less then API 21, add the following to onCreate:

AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);  

Also, Replace your ImageView with android.support.v7.widget.AppCompatImageView

Upvotes: 1

Sachin Soma
Sachin Soma

Reputation: 3822

Replace

app:srcCompat="@drawable/ic_demo"

with

android:src="@drawable/ic_demo"

Upvotes: 0

forpas
forpas

Reputation: 164164

The drawable ic_demo can't be found.
Make sure that this drawable is in res/drawable folder and not in another folder like drawable-v21 or drawable-v24

Upvotes: 0

Related Questions