R.java disappears completely, won't regenerate - HELP!


#1

Hi,

i had 2 errors that i did not know how to resolve, so i thought i would try to clean my project. well, turns out that completely erased R.java because it would not auto-generate, since i had errors (or so i’ve read on stack overflow)… but now i have like 20 red errors having to do with R not being recognized as a field (obviously, since there is no R.java anymore), but how do i get my R.java back?

i tried these things that didn’t work, as seen on stack overflow:

  1. delete your tools in the Android SDK, then reinstall. refresh your project. - nope, didn’t work.

  2. comment out all your errors, then clean your project again. - i can’t because there are so many!

  3. use ANT - i have no idea how to use ANT, unfortunately, just a beginner.

  4. close Eclipse then open again. - nope, didn’t work.

anyone have any other ideas?!?! PLEASE can a monitor chime in? this is the most stuck since i’ve started this book, and if Stack Overflow can’t help, i really only have you guys. thank you so much.


#2

UPDATE:

just as you give up hours and hours later, something changes and you break through. so here is the solution!

i decided to check all my errors again, and try to fix the non-R.java related ones, and managed that okay. then i decided to just try the method of //commenting out all of my R.java related errors i found in my QuizActivity.java file. this ended up commenting out 80% or more of my project. but i managed it, without generating new errors. so then i “cleaned my project” again, and this worked! it regenerated my once missing R.java file.

BUT! now i had new errors. basically any code that started out with the R.type.variable now had errors on those lines. it’s as if the variables in that file were not being recognized by R.java, even though I checked R.java and all my variables had ids. so then i noticed a very small import file called, import android.R in my QuizActivity.java, and a little yellow warning by it. i clicked the warning out of curiosity, and it said the import should not be there (i never put it there, it was auto-generated when i got my R.java back) and warned that this code could cause other errors. and that’s exactly what it did. so i deleted that import and like magic, all the red errors went away! but take note, updating my imports by using the [command]+[shift]+[O} did not remove the import, i had to manually remove it.