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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:04:34  来源:igfitidea点击:

R.drawable cannot resolve image

javaandroiddrawable

提问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.Rdiffers 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.Ris 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。还要检查您是否已保存必须在其中膨胀图像的布局。