Home » Android » image – Android: failed to convert @drawable/picture into a drawable

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

Posted by: admin March 11, 2020 Leave a comment

Questions:

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

How to&Answers:

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

Answer:

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

Answer:

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

Answer:

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!

Answer:

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

Thanks

Answer:

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).

Answer:

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.

Answer:

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

Answer:

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.

Answer:

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 🙂

Answer:

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

Answer:

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.

Answer:

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.

Answer:

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.