【问题标题】:Android Studio - Failed to convert @drawable/ into a drawableAndroid Studio - 无法将 @drawable/ 转换为可绘制对象
【发布时间】:2015-07-05 10:24:20
【问题描述】:

当我尝试在布局文件中使用图像时出现此错误:

Couldn't resolve resource @drawable
Failed to convert @drawable/image into a drawable

这是我的布局文件

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/image"
        />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

我尝试重新启动 IDE,clean-rebuild 但没有,我阅读了所有与之相关的线程(我认为)。 是的,我的图片名称仅包含 [a-z0-9_.]。

【问题讨论】:

  • 图片名称和扩展名是什么?
  • 检查资源名称是否包含非法字符
  • @itzhar 名称是“image.png”,但我试图删除扩展名,同样的错误
  • @jlopez 它不包含我在问题中提到的任何非法内容
  • 我确定你看到了这个帖子*.com/questions/8874262/…。无论如何,请确保您没有任何其他同名文件

标签: android


【解决方案1】:

我遇到了同样的问题,我通过将我的图像重命名为类似的东西来解决它:my_image。

【讨论】:

  • 正如我所说,图像的名称是正确的,我仍然有这个错误
  • 您是否在名称中添加了任何“_”?如果没有尝试。有时 Android Studio 会给这种“愚蠢的东西”带来问题。
【解决方案2】:

好吧,我找到了避免这种情况的方法

RightClickdrawable 文件夹上然后New => File 插入其名称(myImage) 例如然后选择Image Files

然后在drawable 文件夹中,我将myImage 文件替换为真实图像。

【讨论】: