1

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.

10
  • Make sure your image /ic_demo is in res/drawable folder not in drawable-v24 Commented Oct 26, 2018 at 10:11
  • Paste your xml code. Very difficult to debug without haveing a look at it. Check if you're getting an error in xml Commented Oct 26, 2018 at 10:12
  • can't find resource in your project error means Commented Oct 26, 2018 at 10:12
  • use AppCompatImageView rather than ImageView, that might solve your issue. Commented Oct 26, 2018 at 10:13
  • do not use this app:srcCompat="@drawable/ic_demo" use : android:src Commented Oct 26, 2018 at 10:29

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

can you generate vector graphic from android studio and test with that image. looks like your vector graphic might not be supported.
it used to work on below gradle 3.0 but from today i'm facing this issue.
Found an issue. some of the vector are not supported and some of them are. but in lower version all of the vector used to work perfectly. can you suggest some me how do i convert PNG to SVG?
you can check supported tags for backwards compatibility from this link. developer.android.com/studio/write/vector-asset-studio
0

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

2 Comments

it's already in res/drawable not in v21 or v24 still i'm facing that issue
Then clean project and if needed invalidate/restart
0

Replace

app:srcCompat="@drawable/ic_demo"

with

android:src="@drawable/ic_demo"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.