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?
-
1Never mind. I figured it out. For some reason, it was importing android.R – Andy Hin May 01 '11 at 02:51
-
2It happens when you aren't careful with importing R. – Haphazard May 01 '11 at 02:52
-
Can you share what was the issue? This will help for others. So try to put what was error. – Pankaj Kumar May 01 '11 at 04:25
-
Hey Pankaj, i've added my own answer. – Andy Hin May 03 '11 at 18:24
8 Answers
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.

- 30,345
- 42
- 99
- 142
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;

- 2,055
- 2
- 18
- 23
-
After adding the drawable resource you want to use and rebuilding the application, this is really all you need. – Machado May 02 '23 at 22:29
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.

- 171
- 1
- 1
- 7
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.

- 353
- 4
- 9
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.

- 147
- 8
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.

- 11
- 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
With me it worked after the following steps
Configure -> SDK Manager -> Android SDK -> SDK Tools -> Checked NDK -> Apply
Restart Project

- 353
- 4
- 9