1

I have been having a lot of trouble because of an apparent bug in the latest java release, that has stopped me and many other people it seems, from referencing images. For example, the following code will not compile, even though this is the code given by many sites:

ImageView imageView = (ImageView) findViewById(R.id.myimageview); imageView.setImageResource(R.drawable.myimage); 

(or to a similar effect)

What I'm looking for is an alternate way to access an image from the file system, without using said "R.drawable.*".

5
  • 3
    Hmm.. I haven't faced such problems, could you elaborate in more detail what kind of compile errors you're getting? Commented Dec 31, 2011 at 0:37
  • sure, for example, eclipse tells me that the icon in; Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.icon); "cannot be resolved or is not a field" Commented Dec 31, 2011 at 1:03
  • Actually, give me a little longer, I don't want to confuse anyone Commented Dec 31, 2011 at 1:06
  • maybe your R.java is not generated? actually this is a common error, but surely it is not a bug in java Commented Dec 31, 2011 at 1:30
  • I would say that there is a problem in R generation, too. I have seen such problems and always I had to correct some resource name or clean or wipe/rebuild the R. Commented Jan 3, 2012 at 16:03

3 Answers 3

2

2 possibilities:

Clean your project (Project>Clean). This will probably also fix your R.java file.

Check your imports! Possible that you've imported the R class. Had lots of trouble with that too.

If you're really looking for an alternative, look at Assets.

EDIT

If the above doesn't fix it, check your res folder (incl subfolders) for suspicious files, and delete them. like for example files that won't open, have no extension, or have errors in them.

Sign up to request clarification or add additional context in comments.

Comments

0

Is that the error that you're getting when you compile the code that you've posted? I've never seen this error before. I would suggest doing a Project --> Clean and if that doesn't work delete the R file in the gen folder and then rebuild.

Comments

0

seen the same problem,make sure you have not imported the .R package,if so remove it from th list of imports,delete the R.java class ,clean then rebulid the project.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.