Android: failed to convert @drawable/picture into a drawable

AndroidImageAndroid LayoutReferenceDrawable

Android Problem Overview


In my drawable folder I have a few images and they all reference perfect, but when I try and add any more images with the exact same size in the same folder, and try to reference it, is flags up an error "Failed to convert @drawable/picture into a drawable". I have tried the same image with a different name and it just keeps giving me that error. I have also tried it in a different XML layout and the same thing. Also the name of the picture have been "jack", "abc", "question_mark" as you can see there are strictly in the rules of the what characters you can use, and still the error message keeps coming up. Any advice would be great on how to fix the problem, thanks.

> Failed to convert @drawable/picture into a drawable

Android Solutions


Solution 1 - Android

Restart Eclipse (unfortunately) and the problem will go away.

Solution 2 - Android

Also check if the resource-name contains any illegal characters (for me it was a "-" in my-image)

Solution 3 - Android

If re-starting Eclipse does not correct the problem, make sure that the image name begins with an alpha character (non-numeric).

Solution 4 - Android

file name must contain only abc...xyz 012...789 _ . in Resources folder.

for ex:

my-image.png is False!
MyImage.png is False!
my image.png is False!
...
...

my-xml.xml is False!
MyXml.xml is False!
my xml.xml is False!
...
...

Solution 5 - Android

This is because your Image name contains "-" symbol . the only allowed characters are [a-zA-Z0-9_.]

Thanks

Solution 6 - Android

I have the same problem on Android Studio. No need to restart the IDE, just close and reopen the project and that will resolve the problem. (Make sure the src are correclty input).

Solution 7 - Android

In Android Studio your resource(images) file name cannot start with NUMERIC and It cannot contain any BIG character. To solve your problem, do as Aliyah said. Just restart your IDE. This solved my problem too.

Solution 8 - Android

Simplify the name of your file, seems to be that any special characters in the file name makes it hiccup. for example chaange "my-main-header.png" to "header1.png" not sure why, but it works

Solution 9 - Android

For Android Studio I had this same problem. It was caused by running from linux, meaning the files did not automatically receive an extension. By manually adding .png to the end of the filenames it could recognize the filetype and load accordingly.

Android studio might throw a hissy fit if you try to refactor rename inside the project, because android will try to regenerate R immediately. I do not know exactly what causes the error as it points to some seemingly random line of code, which in my case was a comment.

Solution to that: Delete from drawable, rename outside of the project and throw them in again.

Solution 10 - Android

It can be even more trivial than what the other posters suggested: if you have multiple projects make sure you did not create the xml layout file in the wrong project.

After creation, the file will open automatically so this might go unnoticed and you assume it is in the correct project. Obviously any references to drawables or other resources will be invalid.

And yes, I am that stupid. I'll close any unused projects from now on :)

Solution 11 - Android

I think I found a way to have it work without restarting Eclipse, or without closing project (it worked for me):

  • rename image file name under res/ in Eclipse -> choose file and press F2 (for me it res/drawable-mdpi/bush-landscape.jpg -> changed to bush.jpg)

  • Build Project (it will still show error)

  • change image where you used it (I changed in Graphical Layout. For me the place was LinearLayout/Background/bush-landscape -> changed "bush-landscape" to "bush")

  • Build Project

Solution 12 - Android

My Image name was 21.jpg. I renamed it as abc.jpg and it worked. So Make sure your image name not starting with a number. However all above answers are also accepted.

Solution 13 - Android

If you have the naming conventions right, then just go to File -> Invalidate Caches / Restart..

And press Invalidate Caches / Restart..

This helped in my case.

Solution 14 - Android

In my case I had an image in different folders (with same name) for supporting different dpi and device sizes. All images had same name except one of them. It was mistyped and once I renamed it like other names, it resolved my issue.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJack TrowbridgeView Question on Stackoverflow
Solution 1 - AndroidAndroliyahView Answer on Stackoverflow
Solution 2 - AndroidperumerView Answer on Stackoverflow
Solution 3 - AndroidGregMView Answer on Stackoverflow
Solution 4 - AndroidMahdi-bagvandView Answer on Stackoverflow
Solution 5 - AndroidKibaView Answer on Stackoverflow
Solution 6 - AndroidYen NQView Answer on Stackoverflow
Solution 7 - AndroidSabri MevişView Answer on Stackoverflow
Solution 8 - AndroidraymondView Answer on Stackoverflow
Solution 9 - AndroidG_VView Answer on Stackoverflow
Solution 10 - Androiduser1883611View Answer on Stackoverflow
Solution 11 - AndroidAlexView Answer on Stackoverflow
Solution 12 - AndroidAbhishek KaushikView Answer on Stackoverflow
Solution 13 - AndroidAmit UpadhyayView Answer on Stackoverflow
Solution 14 - AndroidHamidView Answer on Stackoverflow