Resource Not Found exception on below Lolliopop Devices - android

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.

Related

Binary XML file line #587: Error inflating class ImageView

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

How to use Android vector drawables as background for an activity?

I am unable to set a vector drawable xml as background in an Android activity.
I tried to set it as background by setting android:background="#drawable/test_background"
to the Coordinator layout root of my activity.
to the Coordinator layout child Constraint layout
to an ImageView child of the ConstraintLayout via app:srcCompat"= #drawable/test_background"
None of the above approaches worked. I can see only a black screen in the design preview, and my application crashes with a Fatal exception:
android.view.InflateException: Binary XML file line #5: Error
inflating class android.support.design.widget.CoordinatorLayout
Here is an outline of my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/test_background"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:scrollbarStyle="outsideOverlay">
<android.support.constraint.ConstraintLayout>
<android.support.v7.widget.AppCompatImageView>
</android.support.v7.widget.AppCompatImageView>
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
The test_background drawable is an xml vector asset created from a png image, converted to an svg in Inkscape, and exported into an xml asset via an Inkscape plugin. The png image contains a kind of pattern, and I never really transformed anything on it to a path. So it looks like this:
<vector xmlns:ns0="http://schemas.android.com/apk/res/android"
ns0:name="svg869"
ns0:width="1382.2272dp"
ns0:height="2073.3408dp"
ns0:viewportWidth="666.666666667"
ns0:viewportHeight="1000.0"/>
However, I did confirm that the plugin is exporting the xml successfully because I can set the xml background successfully as an icon (for example as a logo/icon).
My problem is that I cannot set the vector as background.
Are there any attributes that I need to set within the drawable in order to use it as background for an activity? Or am I doing something wrong?
Thanks a lot for any help!
You need to convert your SVG into an Android Vector Asset. You can easily do this with Android Studio.
Right click your project > New > Vector Asset. Then Select "Local File" and enter the file location/path
As described here you must create a new layer drawable to hold vector drawable. This implementation is for Pre-Lollipop devices. Devices with Lollipop and above don't need this. I've tested it and it works i.e irrespective of the type of rootview you have.

ImageView stopped showing image

ImageView suddenly stopped showing image. It was showing image and then suddenly it stopped showing image(Not sure what i did)
Here is how its look in Design view
Image exists in res/drawable
ImageView Tag
<ImageView
android:id="#+id/background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/background" />
I have tried clean project still not resolve. Design view doesn't show any rendering errors
Try removing the background.png from the drawable-xhdpi folder and into the regular drawable folder. That looks like the error to me. You can try doing it in Windows Explorer if it is hard in Android Studio. Just look through the project files.

android bitmap "no resource found error"

i have bg.xml and texture.png in res/drawable folder.
bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/texture"
android:tileMode="repeat" />
in my layout file i use it as
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg">
and in design screen no rendering problems occur and virtual device shows the background image (texture.png) properly.
but when i run the app
No resource found that matches the given name (at 'src' with value '#drawable/texture').
error happens.
what might be the problem?
Be sure you have a texture.png in one of your drawable folder (.png or what you prefer).
Try to clean your project via Studio or the Gradle console (there is also an option if you're on Eclipse)
(On Studio only) There is an menu called restart and invalidate cache, use it if the step 1 and 2 didn't solve your issue
My image was .jpg and i just changed extension to .png.
Later i used paint save as png and updated the image in the drawable folder.
That solved the problem.

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