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

前端 未结 14 1765
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 10:16

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 refe

相关标签:
14条回答
  • 2020-12-02 10:44

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

    0 讨论(0)
  • 2020-12-02 10:44

    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

    0 讨论(0)
  • 2020-12-02 10:45

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

    0 讨论(0)
  • 2020-12-02 10:47

    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

    0 讨论(0)
  • 2020-12-02 10:47

    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.

    0 讨论(0)
  • 2020-12-02 10:47

    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.

    0 讨论(0)
提交回复
热议问题