Andy Hin
Andy Hin

Reputation: 31893

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?

Upvotes: 17

Views: 18783

Answers (8)

Diraph
Diraph

Reputation: 327

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.

Upvotes: 1

Gianmarco G
Gianmarco G

Reputation: 381

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 a-z, 0-9, or underscore.

Upvotes: 1

Gianmarco G
Gianmarco G

Reputation: 381

With me it worked after the following steps

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

Restart Project

Upvotes: 0

Rhys
Rhys

Reputation: 2173

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;

Upvotes: 11

Shervin R
Shervin R

Reputation: 1

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

Upvotes: 0

faraquet99
faraquet99

Reputation: 181

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.

Upvotes: 2

ama_trig
ama_trig

Reputation: 11

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.

Upvotes: 1

Andy Hin
Andy Hin

Reputation: 31893

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.

Upvotes: 38

Related Questions