3

I am new to Android development. To implement a photo gallery app, tutorial said to add images to res/drawable and access them via R.drawable.image1 .. etc. But there is no drawable folder default in eclipse, then I created a one and add images. But cannot access images, there is no option in R.drawable. as "image1"

Any idea ?

3 Answers 3

3

you should create "drawable" folder under "res", and you'd best place png image files in that folder. When accessing these image files programmingly.set an image for an ImageView for example:

Drawable imgDrawable=getResources().getDrawable(R.drawable.yourImageFileName));
imgView.setImageDrawable(imgDrawable);
1
  • Thanks, I had a similar issue regarding menu, Should there be a default "menu" folder in /res/ ? I donr have a one. So i created a one. But I cant access it as "R.". But when I create a drawable it can be accessed. Apr 18, 2011 at 6:46
3

Sometimes the drawable folder is not created by default Instead it will have "drawable-hdpi","drawable-mdpi" and "drawable-ldpi".These folders are for placing images for various screen densities to support different resolutions.Your "drawable folder" is for baseline medium density.

In your case create a folder named "drawable" under "res" and place your image inside that folder and you will be able to access it using R.id.imagename .Try refreshing the project and check whether you have created the drawable folder under the res folder.Also check the case of the folder name that you have created.

2
  • Thank you very much for the quick response. Got it. I was not directly copying images to that folder, I was rather importing them as a file. So it keeps a reference.Thats why I couldn't access R.drawable.image. And you are correct. I do not have drawable folder by default. but has those other ones. Apr 18, 2011 at 6:15
  • It should work for you as mentioned above.Also take note that even if you place it in the other drawable folders such as mdpi,ldpi and hdpi you should be able to access the image.
    – rogerstone
    Apr 18, 2011 at 6:18
0

I faced same problem , but when i added those images again in jpg format it worked. Might work for you too. My System was based on windows 10 & was using android studio 4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.