Error inflating class ImageView

♀尐吖头ヾ 提交于 2019-12-03 10:06:08

I had the same problem. my problem has occurred because I just had used images (icons) in the "drawable-v24" folder. I solved it by copying them into "drawable" folder

I came across this same problem recently and was able to solve it using app:srcCompat="@drawable/ic_black_image_24"

The documentation of appcompat:srcCompatstates that -

It sets a drawable as the content of this ImageView. Allows the use of vector drawable when running on older versions of the platform.

Hope this helps if anyone stumbles upon the same problem.

try to change

v = View.inflate(getContext(), R.layout.event_show_row_layout, null);

to

v = View.inflate(getApplicationContext(), R.layout.event_show_row_layout, null);

For me, inside one of my layout.xml files, I had

<ImageView
    android:id="@+id/row_1_col_0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@string/default_picture_location">
</ImageView>

and inside strings.xml, I had

<string name="default_picture_location">"@mipmap/tile"</string>

and so it was showing this in Android Studio:

<ImageView
    android:id="@+id/row_1_col_0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/tile">
</ImageView>

I thought everything would work because there were no errors and the application compiled and ran. However, there was a run time error that said "android.view.InflateException: Binary XML file line #7:Error inflating class ImageView".

Once I changed android:background from

android:background="@string/default_picture_location"

to

android:background="@mipmap/tile"

everything worked.

It's an old question but I just came across the same problem. In my case it was caused by using the android:tint attribute with an selector rather than a color:

<ImageView
    ...
    android:tint="@drawable/some_selector" />

While this works without a problem a SDK 21+ it crashes in older versions...

Switching to AppCompatImageView and to app:tint solved the problem:

<android.support.v7.widget.AppCompatImageView
    ...
    app:tint="@drawable/some_selector" />

For me , i copy my image to Folder drawable-v24 and compiler didnt find it

Change view of Android studio to project view

and cut and paste your image to folder drawable

The error during inflation might come from drawable used in the ImageView, in this case:

android:background="@drawable/timeline_image_border"
android:src="@drawable/timeline_image_dummy"

To get rid of it, replace all the existing images trying a different drawable.

I have the resources in the drawable-zh-xxhdpi catalog documents, but not in the drawable-xxhdpi catalog of resources, the emergence of this mistake.

This should be:

res
  drawable-xxhdpi
     aa.png
  drawable-zh-xxhdpi
     aa.png

you haven't closed LinearLayout tag

and please use following code for inflating layout.xml

LayoutInflater inflater = getLayoutInflater();
final View v = inflater.inflate(R.layout.your_layout_id, null);

In my case I had the same error, but only when using a device with API < 24 (emulator or physical device).

This was caused by the use of "gradient" inside a SVG I imported.

The error do not appear in the stacktrace, but it appears in the .xml of the imported SVG file:

This causes the app to crash when inflating a View that has this SVG as its source, for APIs < 24.

If you want to use SVG only, you can restrict the use of this resource to APIs >= 24 and remove the gradient for APIs below.

Putting image in drawable NOT as "v-24" worked for me and I stopped get the crash.

I myself had this problem because my image was in darawable-v24 directory. so when I wanted to use older api, the app was crashing. so I suggest to check whether you're resource is in correct directory or not.

luqman ahmad

For me it works when I paste image in both drawable and drawable-v24 and I added some code android:src="@drawable/battman"

Don't name xml file and image file the same name like this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!