Error inflating class ImageView
Asked Answered
F

18

43

I've been getting InflateException/ClassNotFoundException error intermittently. I've seen similar errors before in SO but they were caused by spelling errors. I spelled 'ImageView' correctly so I don't know what's causing the error.

The code where the error occurs is:

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

Here's the layout xml:

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

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="10dip"
        android:paddingRight="10dip" >

        <TextView
            android:id="@+id/fromTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp"
            android:textStyle="italic" />

        <TextView
            android:id="@+id/timeTextView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:textSize="12sp"
            android:textStyle="italic" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/layoutPostImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="4dp" >

        <ImageView
            android:id="@+id/postImageView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_margin="2dp"
            android:adjustViewBounds="true"
            android:background="@drawable/timeline_image_border"
            android:contentDescription="@string/hello"
            android:paddingBottom="6dp"
            android:scaleType="fitXY"
            android:src="@drawable/timeline_image_dummy" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/wordsRelativeLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/wordsTextView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|center_horizontal"
            android:paddingLeft="50dp"
            android:paddingRight="50dp"
            android:text="@string/hello" />

        <ImageView
            android:id="@+id/topLeftQuoteImageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:adjustViewBounds="true"
            android:contentDescription="@string/hello"
            android:maxHeight="25dp"
            android:maxWidth="25dp"
            android:scaleType="fitXY"
            android:src="@drawable/po_quotes_mobile1" />

        <ImageView
            android:id="@+id/bottomRightQuoteImageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="12dp"
            android:layout_marginRight="12dp"
            android:adjustViewBounds="true"
            android:contentDescription="@string/hello"
            android:maxHeight="25dp"
            android:maxWidth="25dp"
            android:scaleType="fitXY"
            android:src="@drawable/po_quotes_mobile2" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp" >

        <Button
            android:id="@+id/commentButton"
            android:layout_width="84dp"
            android:layout_height="24dp"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="5dp"
            android:background="@drawable/es_comment_btn" />

        <Button
            android:id="@+id/buttonLike"
            android:layout_width="84dp"
            android:layout_height="24dp"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@id/commentButton"
            android:background="@drawable/es_like_btn" />

        <Button
            android:id="@+id/buttonNumberLike"
            android:layout_width="wrap_content"
            android:layout_height="24dp"
            android:layout_gravity="center"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@id/buttonLike"
            android:background="@drawable/like_counter"
            android:textColor="@android:color/white"
            android:textSize="12sp" />

        <Button
            android:id="@+id/buttonDelete"
            android:layout_width="38dp"
            android:layout_height="24dp"
            android:layout_alignParentRight="true"
            android:layout_marginRight="5dp"
            android:background="@drawable/es_more_btn" />
    </RelativeLayout>

    <TextView
        android:id="@+id/commentsTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:background="#FFF9F8F1"
        android:text="@string/hello"
        android:textColor="@android:color/black"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/spacerTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp" />

</LinearLayout>

Here is the error log:

E/AndroidRuntime(15849): FATAL EXCEPTION: main
E/AndroidRuntime(15849): android.view.InflateException: Binary XML file line #36: Error inflating class ImageView
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.createViewFromTag(LayoutInflater.java:454)
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.rInflate(LayoutInflater.java:737)
E/AndroidRuntime(15849):    at  org.holoeverywhere.LayoutInflater.rInflate(LayoutInflater.java:740)
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:542)
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:492)
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:487)
E/AndroidRuntime(15849):    at android.view.View.inflate(View.java:8807)
E/AndroidRuntime(15849):    at com.mypackage.adapters.PostAdapter.getPostView(PostAdapter.java:283)
E/AndroidRuntime(15849):    at com.mypackage.adapters.PostAdapter.getView(PostAdapter.java:268)
E/AndroidRuntime(15849):    at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
E/AndroidRuntime(15849):    at android.widget.AbsListView.obtainView(AbsListView.java:1430)
E/AndroidRuntime(15849):    at android.widget.ListView.makeAndAddView(ListView.java:1745)
E/AndroidRuntime(15849):    at android.widget.ListView.fillDown(ListView.java:670)
E/AndroidRuntime(15849):    at android.widget.ListView.fillFromTop(ListView.java:727)
E/AndroidRuntime(15849):    at android.widget.ListView.layoutChildren(ListView.java:1598)
E/AndroidRuntime(15849):    at android.widget.AbsListView.onLayout(AbsListView.java:1260)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at net.simonvt.menudrawer.LeftDrawer.onLayout(LeftDrawer.java:64)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
E/AndroidRuntime(15849):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
E/AndroidRuntime(15849):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(15849):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(15849):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(15849):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(15849):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(15849):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(15849):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(15849):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(15849): Caused by: java.lang.ClassNotFoundException: Could not find class: ImageView
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.onCreateView(LayoutInflater.java:607)
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.createViewFromTag(LayoutInflater.java:448)
E/AndroidRuntime(15849):    ... 48 more
Footrope answered 22/5, 2013 at 17:41 Comment(5)
plz also add event_show_row_layout layout xml with question to get more help from usGoodwill
just added the layout xml. thanks!Footrope
The problem described in this question seem similar. #15190457Whacking
Try on device. Many times it's the issue with the emulator.Conidiophore
The error during inflation might come from drawable used in the ImageView, misspelled the name of an png file that was used in this imageview so the file cannot be found. Stupid and crptic error for "file not found". Sigh, I really hate the complexity of Android.Contrary
M
79

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

Monied answered 16/5, 2018 at 20:40 Comment(0)
C
25

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.

Coorg answered 28/8, 2017 at 10:52 Comment(1)
Thank you so much this is the culprit for meVendetta
R
10

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

Change view of Android studio to project view

Project View

and cut and paste your image to folder drawable

Railroader answered 17/8, 2018 at 18:1 Comment(0)
B
9

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.

https://stacklearn.ir

Batt answered 24/2, 2019 at 9:4 Comment(0)
S
8

I had the same issue, because I copied my png files to drawables while on Android view, and it automatically copied to drawable-v24, but you need to copy your files to drawable, you can navigate to your project and then res/drawables and paste it manually, or change your view to project view the past it in the drawable folder

Sterrett answered 24/4, 2020 at 17:5 Comment(0)
S
7

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" />
Sporophyll answered 27/4, 2018 at 8:1 Comment(0)
B
5

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);
Birefringence answered 29/7, 2013 at 12:14 Comment(0)
T
4

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.

Testerman answered 30/10, 2015 at 1:5 Comment(1)
The reason this didn't work is because you had quotes between the string tags; they are not needed.Thoracoplasty
Q
3

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
Quiz answered 14/2, 2017 at 10:23 Comment(0)
H
3

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

Hep answered 4/12, 2018 at 11:17 Comment(0)
M
2

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.

Monkish answered 7/10, 2016 at 10:30 Comment(1)
I misspelled the name of an png file that was used in this imageview so the file cannot be found. Stupid and crptic error for "file not found". Sigh, I really hate the complexity of Android.Contrary
G
2

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:

enter image description here

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.

Galle answered 22/11, 2017 at 9:53 Comment(0)
B
2

Don't name XML file and image file the same name like this:

enter image description here

Bitternut answered 21/5, 2019 at 3:35 Comment(0)
M
1

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);
Maggard answered 29/7, 2013 at 12:6 Comment(1)
sometimes, because of the editor behavior or bug in editor, it doesn't throw any error , instead it will run on emulator or device. but Android is very smart than editor, it will catch the error and doen not inflate the xml to create layout.Maggard
M
1

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

Marleen answered 21/2, 2019 at 22:16 Comment(0)
C
1

In my case it was SVG image with long paths. It showed error:

Caused by: java.lang.IllegalArgumentException: R is not a valid verb. Failure occurred at position 2 of path: STRING_TOO_LARGE

Looking at long SVG Asset file error : R is not a valid verb. Failure occurred at position 2 of path: STRING_TOO_LARGE I splitted paths into several below 32Kb.

Christopherchristopherso answered 2/2, 2021 at 13:15 Comment(0)
F
0

For me the problem was that the svg-file was to big.

Fortdefrance answered 4/4, 2020 at 17:7 Comment(0)
N
0

In my case the svg had letters that have gaps and then this caused the bug, what I did was modify the letters in illustrator removing the gaps and it worked.

Natalienatalina answered 10/6, 2020 at 2:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.