Binary XML file line #587: Error inflating class ImageView - android

I have gone through multiple answers on StackOverflow but still not clear how to fix this crash.
I am getting this crash from Firebase,
"Fatal Exception: java.lang.RuntimeException Unable to start activity
ComponentInfo{com.Activity}: android.view.InflateException: Binary XML
file line #587: Binary XML file line #587: Error inflating class
ImageView"
enter code here
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_img" />
I am using a drawable image, I have kept images in all folders mdpi,hdpi,xdpi,xxhdpi,xxxhdpi. (And I am not using vector image). I have tried running my app on all resolution emulators not able to reproduce this crash but still seeing it in crashlytics very frequently. Happening majorly in samsung, oppo,Vivo.
Do i need to keep same image in a drawable folder as well if I am keeping them in drawable-hdpi, drawable-xhdpi...folders.
Can anyone please help me with how to fix this crash?

I have also faced the same problem. Try the steps below, it may also work for you:
Rename the drawable name.
update the drawable name in the image view.
Clean and rebuild the project.
Run the app.

Check if your drawable image was inside of drawable-v24. If it is move it to drawable folder

Related

Resource Not Found exception on below Lolliopop Devices

android.view.InflateException: Binary XML file line #2: Error
inflating class
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/myimage"
android:orientation="vertical" >
</LinearLayout>
On Lollipop and Marshmallow devices Image is loading.
I am Using Android Studio and Material Design Theme
As suggested by some posts Cleaned the project,Lower size image is also added
still no luck
It got resolved after adding drawable folder and copying all images to drawable folder.
Whatever images I copied to drawable folder was added to drawable-v21 folder(it is shown as myImage(V21 inside drawable folder)).
So for pre Lollipop devices there is no image hence it was crashing.

How to fix android error 'Color value must start with #'?

I was trying to use an icon from this page in my layout as follows
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_backspace_black_24dp"
/>
but it could not be rendered because of an error
Color value '#drawable/ic_backspace_black_24dp' must start with #
I found two related issues in SO here and here which did not help resolve the issue.
There is no dash ('-') in the filename, the file-format is a 'png' and there is no res/color directory in my project.
All my colors defined in colors.xml start with a #.
So how to fix this error?
Simply rename your file name by removing the numbers and only keep lower case letters or underscores.
Problem solved: I forgot to remember that the android sources on the internet are really outdated, and almost none of the documentation works as-is!
The folder res/drawable as suggested in the android developer guide is deprecated! The folder is now named mipmap! So the simple solution is to have the following layout to fix the problem:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_backspace_black_24dp"
/>
Never trust the android developer documentation ... !
Try removing the '_" underscores and make the name shorter. Not sure why but that worked for me.
Check the file drawable/ic_backspace_black_24dp.
If you downloaded the SVG version you will able to open as a text file. Check if the android:fillColor has the #.
Anyway if you are using Android Studio those icons can be downloaded very easily using Vector Asset Studio:
Right click in drawable
new
vector assets
choose the icon you want
You have more info of this feature here.

ClassCast Exception Android Studio

I am getting a ClassCastException in android studio while running my project. Can anyone tell me what is causing this error.
ClassCastException: com.intellij.psi.impl.source.PsiPlainTextFileImpl cannot be cast to com.intellij.psi.xml.XmlFile
Thanks.
Sovled this atlast. This Question helped me. Android Studio ClassCastException When Attempting to Open A Layout XML File . I had a 11MB xml file in values. That was the problem. After deleting that, the problem was solved.
And if you want to use a large XML file add the below code in idea.properties and vmoptions in the bin folder of Android Studio.
**Add in idea.properties**
#------------------------------------------------------------- --------
# Maximum file size (kilobytes) IDE should provide code assistance for.
# The larger file is the slower its. editor works and higher overall system memory requirements are
# if code assistance is enabled. Remove this property or set to very. large number if you need
# code assistance for any files available regardless their size.
#---------------------------------------------------------------------
idea.max.intellisense.filesize=999999
**Add in vmoptions**
-Didea.max.intellisense.filesize=999999 # <--- new line
Reference: https://stackoverflow.com/questions/23057988/file-size-exceeds-configured-limit-2560000-code-insightfeatures-not-availabl
It would be better if you can share some code snippets...
Anyways, as far as ClassCastException is concerned, it means you are declaring a variable of some type and assigning it to another type you have defined in a layout xml file...
for example, in the xml you may have had:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_height="wrap_content"
android:id="#+id/btn1"
android:layout_width="wrap_content">
</Button>
</LinearLayout>
but while connecting the component to code:
ImageView img1 = (ImageView)context.findViewById(R.id.btn1);
This will fire a ClassCastException because you are casting a Button to an ImageView variable which is as you understand not possible!
If this doesn't solve your problem then it would be better if you post some code snippets after figuring out which code snippet causes the error!

Android FileNotFound Exception on custom.xml in the drawable-hdpi folder

I keep getting a FileNotFound Exception, and quite frankly, it makes no sense. Here are my files:
custom.xml
<item android:drawable="#drawable/easymode"></item>
main.xml
<Button android:id="#+id/guess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:layout_marginBottom="20dp"
android:onClick="myClickHandler"
android:background="#drawable/custom"></Button>
I've tried moving the background tag above the others to see if that was causing it to fail, it didn't work. I've moved the custom.xml file into a drawable folder, and into the ldpi and mdpi folders but it keeps giving me the same error. Why can't it find my custom.xml when it's quite clearly there? R.java also lists it, so I know it's generated the link to it successfully... Help!
Have you tried building the R file again after saving? It can be a little confusing when working with the Android SDK in Eclipse (i'm guessing you are using Eclipse). After adding your new layout xml, are the ids for buttons and strings correctly parsed and identified in your code?
I would do a save all and then compile the project and then run it and see if this sorts your problem out.
The order of the tags makes no difference here as the layout xmls are compiled into a compact resource.
If it still cannot find the xml I suggest deleting the xml, restart Eclipse and create it again under layout, add your code above to the xml, save, compile and run and see if that sorts it out.

Android XML Viewer failing

I've been having this problem for a while:
Here is my header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/logo_text"/>
</LinearLayout>
And this what the Eclipse/Android XML viewer is giving me:
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
This happens in other projects as well for seemingly random images. Project->Clean doesn't help either. I know this has to be an issue with my machine or eclipse installation because it doesn't happen on my work machine, only my home laptop.
There are no problems when the app is installed, but it would be nice to be able to see layout changes without having to install the app over and over again.
EDIT
I also get these messages anytime I use a custom View in a layout file:
error!
UnsupportedClassVersionError: Bad version number in .class file
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
Exception details are logged in Window > Show View > Error Log
I sometimes have weird issues like this when importing new images into my project. Do you have any other res-image directories with different versions of this file? You may try removing the png and re-adding to the project.
The error message explicitly mentions the -hdpi version of the drawable directory. Have you got that image in all of the different versions of the drawable directory? Perhaps it is in res/drawable-ldpi or res/drawable-mdpi but not res/drawable-hdpi?
If you don't already have one, you could create a plain res/drawable folder and add the image there, then one would expect the system to fall back to that whenever it didn't find a definition-specific version.
Actually try to put an id tag on ImageView : android:id=:"#+id/imageView".Tell me if it is working or not.

Categories

Resources