android.R error if import is present
I just finished debugging one of my apps because I was having issues with R.layout.
Naturally, I went to my .xml files and cleaned up a few errors and everything should have been fine, but it wasn't.
For some reason, I was still getting an error with R.layout saying that my .xml files could not be resolved to a type.
As soon as I deleted the import android.R statement, everything went away and my program compiled correctly.
To my knowledge this is the opposite of what people are saying to do in this situation. Normally they tell you to ADD that statement in to eliminate any errors, but mine was the opposite. Does anyone have any insight as to why this happens so that when this inevitably happens again I won't have to spend as much time on it?
You are importing an R that doesn't contain your application's layout resources. You are instead importing the Android framework's R, thus causing a name collision. There are, however, situations in which you may need android.R. In these cases, you shouldn't import android.R, but instead explicitly use android.R.[whatever] when you need it.
Your application has it's own R which contains most of your application's resources.
android.R contains a variety of Android framework resources.
There is more information on the R class in the Android: What is R? question.
There's two R: your project one and android.R one. You were importing the wrong one
android.R should NOT be imported. It's the system's R.java not your project's. By importing android.R, you are in fact hiding your own R.java and that's why it can't resolve the values inside it. So as you (correctly) did, android.R should be removed from your import list. If you need to use it in your app you can use it like this :