Error inflating class ImageView

I interrupt the InflateException / ClassNotFoundException error periodically. I have seen similar errors before in SO, but they were caused by spelling errors. I spelled "ImageView" correctly, so I donโ€™t know what causes the error.

Error code:

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

Here is the xml layout:

 <?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 
+13
source share
14 answers

I have the same problem. my problem arose because I used images (icons) in the drawable-v24 folder. I solved this by copying them to the drawable folder

+22
source

I recently ran into this problem and was able to solve it using the app:srcCompat="@drawable/ic_black_image_24"

The documentation for appcompat:srcCompat states that -

It sets a valid value for the contents of this ImageView. Allows you to use the vector version when working on older versions of the platform.

Hope this helps if someone runs into the same problem.

+6
source

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); 
+5
source

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 this was shown 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 that everything would work, because there were no errors, and the application was compiled and launched. However, there was a run-time error that said: "android.view.InflateException: binary line of XML file # 7: error inflating the ImageView class."

As soon as I changed android: background from

 android:background="@string/default_picture_location" 

to

 android:background="@mipmap/tile" 

everything worked.

+4
source

This is an old question, but I ran into the same problem. In my case, this was caused by using the android:tint attribute with selector and not with color :

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

Although this works without problems, SDK 21+ it crashes in older versions ...

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

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

An error during inflation can be obtained using the drawable used in ImageView, in this case:

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

To get rid of it, replace all existing images by trying another available one.

+2
source

I have resources in drawable-zh-xxhdpi directory documents, but not in drawable-xxhdpi resource drawable-xxhdpi , this error is occurring.

It should be:

 res drawable-xxhdpi aa.png drawable-zh-xxhdpi aa.png 
+2
source

You did not close the LinearLayout tag

and use the following code to inflate layout.xml

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

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 a โ€œgradientโ€ inside the imported SVG.

The error does not appear on the stack, but it appears in the XML file of the imported SVG file:

enter image description here

This causes the application to crash when inflating the view in which this SVG is its source for API <24.

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

+1
source

For me, I copy my image to Folder drawable-v24 and the compiler did not find it

Change the look of Android studio to view the project

Project view

and cut and paste the image into a drawable

+1
source

I myself had this problem because my image was in the darawable-v24 directory. so when I wanted to use the older API, the application crashed. so I suggest checking if your resource is in the correct directory or not.

+1
source

Putting the image in drawable NOT since "v-24" worked for me and I stopped crashing.

0
source

For me, this works when I insert an image in drawable and drawable-v24 and I added some android:src="@drawable/battman" code android:src="@drawable/battman"

0
source

Do not name the xml file and image file with the same name as this enter image description here

0
source

Source: https://habr.com/ru/post/1482222/


All Articles