java R.drawable 无法解析图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11172582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
R.drawable cannot resolve image
提问by Fasih Awan
I have checked a lot of questions on stackoverflow and I seem to have all the correct things but my R.drawable wont detect my image. It is in /res/drawable and in all the other folders (mdpi, hdpi etc.)
我已经检查了很多关于 stackoverflow 的问题,我似乎拥有所有正确的东西,但我的 R.drawable 无法检测到我的图像。它位于 /res/drawable 和所有其他文件夹(mdpi、hdpi 等)中
ShipImage = context.getResources().getDrawable(R.drawable.player);
And here is my R.java
这是我的 R.java
public static final class drawable {
public static final int background=0x7f020000;
public static final int buttons=0x7f020001;
public static final int dead=0x7f020002;
public static final int enemy=0x7f020003;
public static final int ic_launcher=0x7f020004;
public static final int play_btn=0x7f020005;
public static final int player=0x7f020006;
}
回答by Samir Mangroliya
Are you sure You import import com.yourcompanyname.product.R
?
你确定你进口import com.yourcompanyname.product.R
?
instead of
代替
import android.R;
import android.R;
回答by Naveen Tamrakar
import com.yourcompanyname.product.R
differs from import android.R
import com.yourcompanyname.product.R
不同于 import android.R
First is your project R file, that is generated by SDK.
首先是您的项目 R 文件,它是由 SDK 生成的。
import android.R
is built-in R file, that is provided by Android.
import android.R
是内置的 R 文件,由 Android 提供。
回答by Udit Kapahi
Make sure your image is png. Also check that you have saved the layout where you have to inflate the image.
确保您的图像是 png。还要检查您是否已保存必须在其中膨胀图像的布局。