[android] Android: failed to convert @drawable/picture into a drawable

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

This question is related to android image android-layout reference drawable

The answer is


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

Thanks


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.


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


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


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.


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


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


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


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.


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.


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


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.


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


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to image

Reading images in python Numpy Resize/Rescale Image Convert np.array of type float64 to type uint8 scaling values Extract a page from a pdf as a jpeg How do I stretch an image to fit the whole background (100% height x 100% width) in Flutter? Angular 4 img src is not found How to make a movie out of images in python Load local images in React.js How to install "ifconfig" command in my ubuntu docker image? How do I display local image in markdown?

Examples related to android-layout

How to check if a key exists in Json Object and get its value How to center the elements in ConstraintLayout Android - how to make a scrollable constraintlayout? Add ripple effect to my button with button background color? This view is not constrained vertically. At runtime it will jump to the left unless you add a vertical constraint Is it possible to put a ConstraintLayout inside a ScrollView? Differences between ConstraintLayout and RelativeLayout How to remove title bar from the android activity? How to have EditText with border in Android Lollipop Android: ScrollView vs NestedScrollView

Examples related to reference

Method Call Chaining; returning a pointer vs a reference? When to create variables (memory management) Reference to non-static member function must be called Cannot find reference 'xxx' in __init__.py - Python / Pycharm c++ "Incomplete type not allowed" error accessing class reference information (Circular dependency with forward declaration) C++ initial value of reference to non-const must be an lvalue Dependent DLL is not getting copied to the build output folder in Visual Studio How to write to error log file in PHP How to reference Microsoft.Office.Interop.Excel dll? Linker Error C++ "undefined reference "

Examples related to drawable

How set background drawable programmatically in Android setBackground vs setBackgroundDrawable (Android) Android splash screen image sizes to fit all devices Android - drawable with rounded corners at the top only Android: failed to convert @drawable/picture into a drawable Android get image path from drawable as string How do you obtain a Drawable object from a resource id in android package? How to create Drawable from resource XML shape drawable not rendering desired color How to use default Android drawables