简体   繁体   中英

Android: R.drawable not showing my image?

In my android 2.2 app, I've added my image to the res/drawable-mdpi folder. However, I cannot seem to access it using R.drawable.. As far as I know, there isn't any additional configuration I need to do - any help?

I figured this out. The issue was that the project was importing android.R instead of using the generated R file - if you encounter this problem, check your imports to make sure the correct package/file is being imported.

You need to use a fully qualified name when importing the generated R file. Check your import statements.

Take the following package statement:

package me.rhys.example;

Then the generated R file can be imported using:

import me.rhys.example.R;

I had the same problem for a different reason. In my case I had illegal characters in the image file name and hadn't noticed the console message complaining about it.

Once I'd renamed icon-1.png to icon_1.png all was well.

First click Build -> Rebuild Project so you get help directly from Gradle.
Then please check if your file-based resource name must contain only lowercase az, 0-9, or underscore.

Have Faced the same sort of error, instead of importing contents (pictures) properly, I copied to drawable-hdpi folder, which in turn wasn't generating R Constant ID, you have to import it, rather than just dropping it there.

If you would like to import a file, for example an image file then you need to go to the res/drawable-XXXX and right click on the folder and then select "import" and in the setup select general files and go to the folder where the images are and select the files that you want to import... Netbeans does this automatically but the eclipse lack this feature

With me it worked after the following steps

Configure -> SDK Manager -> Android SDK -> SDK Tools -> Checked NDK -> Apply

Restart Project

Props to Andy Hin This issue can happen if "android.R" was imported. Just check your imports and delete the "android.R" line. It worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM