I’ve been fiddling around with making my own Android apps and I keep running into an issue with my IDE. Out of nowhere it will forget what “R” is and start displaying the error “R cannot be resolved to a variable” and upon hovering over the line it suggests adding a reference to android.R, which does nothing to solve the problem. When I was first starting this caused me to abandon a few project files I had started because I had nothing worth saving and it was just easier for me to start a new project. I figured the answer was some typical pain in the butt java thing like setting the Path properly but it actually turned out to be much simpler.
The issue can most often be solved by going to Project and then Clean in your IDE. After cleaning the project do a fresh build (Ctrl+B) and you should be good to go. Wow, it’s not often that a Java IDE issue is that easily fixed 🙂