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.
Related
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.
I'm getting the error "Failed to convert #drawable/12234 into a drawable" where 12234 is my image name, that is placed inside the drawable folder.
I'm able to assign other images that are smaller, however when I try to assign this image it gives me an error.
Here is my code for my Imageview xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView4"
android:layout_alignParentTop="true"
android:src="#drawable/12234"
android:adjustViewBounds="true"
android:longClickable="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
According to documentation drawables resources must satisfy the following:
File-based resource names must contain only lowercase a-z, 0-9, or _.
And also in your case it cannot be all numbers, it has to have at least one letter.
I solved the issue by renaming the image to have a character first.
Changed image name from 12234.jpg to r12234.jpg
In Adroid Studio's Design View, try just clicking the refresh icon, the one that looks like two curved arrows facing each other.
This worked for me - I didn't need to rename anything or restart my computer.
I'm running ver 1.5.1, Marshmallow, API 23.
I have been stumbling for many hours, read almost all answers on all questions but nothing worked. Finally, I have found a solution that worked.
What i did
Showed "drawable" in explorer
Replaced ALL ı's with i's (drawable-hdpı -> drawable-hdpi, renamed
all folders) Then the folders didn't appear in android studio
Replaced only 2 i's with ı's (drawable-hdpi -> drawable-hdpı, renamed
2 folders) Afterwards, all the images started to appear and finally
i was able to add images.
I'm building an Android App using Eclipse. I'm trying to create a simple image display when the application opens.
I've saved my intro_image.png on res\drawable-hdpi in my workspace, I've created another xml for the layout with the following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/intro_image">
</LinearLayout>
An error message appears when I view the result on the Graphical Layout, saying: "Failed to convert #drawable/into_image into a drawable. Couldn't resolve resource #drawable/intro_image"
How do I solve this?
Thank you.
try to refresh or clean your project. it will work.whenever you paste an image into drawable you have to refresh that folder.
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.
i'm dealing with resources issue for a while and i cannot figure it out. The thing is that my resources(shapes, gradients, layouts) don't load up in application like they should. For instance:
My "layout.xml" file (main layout for activity)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/favourite_rest"
android:orientation="vertical"
android:layout_width="fill_parent"
android:background="#drawable/activ_favourite_bck"
android:layout_height="wrap_content"
android:layout_weight="1">
...
And layout for background: "activ_favourite_bck.xml"
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#55555555"
android:centerColor="#77777777"
android:centerY="0.5"
android:endColor="#55555555"
android:angle="270" />
</shape>
In this case when i run my application, brackground is pure black like no background is set, but when i rename the file with background definition from activ_favourite_bck.xml to "halabala.xml" ( with changing reference in main layout android:background="#drawable/halabala") the background is there and everything is working fine. I want to name my resources with purpuse so later when i have more of them there is no mess. I know there is naming convention that resource filename can contain only small characters with "_" and that's what i'm fallowing.
Note: the file is recognized by IDE, there are no errors during building and i can reference file from code.
I'm woring with android 1.6 api, but i tried changing to 2.0, 2.2.. with no success. I also tried various phone types and emulator and i tried changing IDE from eclipse to IDEA and nothing helps. I tried rebuilding project, refreshing everything that can be refreshed:) i tried to wipe the application from devices with no effect. Is anybody facing similar issue like me?
Btw. the same thing is going on when i put some picture(png) in drawable folder and i'm referencing it from xml. Some pictures are recognized (and shown in running application) and some not( they are recognized only after renaming to sometning else).
Try adding an arbitrary image called a.png or some such (so it sorts alpha above your real drawable) ...
After couple of hours i worked this out. I probaly accidentally removed folder drawable-mdpi. After creating it and copying images there everything works just fine.