I was having a project open in Android studio. It was generated by the wizard and working fine.
I did some small changes to activity_main.xml and when I changed back to MainActivity.java i get the error in several places that it cannot resolve R. I might have done something to cause this. But I´m not sure what since it appered when I edited the xml.
Does anyone know what might be the solution to this? I can find the R.java in r/release/packege/com/ and it looks fine.
R is created as part of building your project. To allow code-completion and other assistance features of Android Studio to work, R gets re-created whenever you add, rename, or remove a resource, as R is an “index” of all of the resources in your app.
The cannot find symbol error, also found under the names of symbol not found and cannot resolve symbol , is a Java compile-time error which emerges whenever there is an identifier in the source code which the compiler is unable to work out what it refers to.
R. java is the generated file by ADT or Android studio. It will be located under app\build\generated\source\r directory.
In JavaLanguage, if you get 'cannot resolve symbol', you have used a name that the compiler hasn't recognized. Class names -- If it is a class name, the compiler cannot find the class.
I just had this problem and the reason was that after editing the layout android studio automatically added an import to the source files:
import android.R
Of course the main R class has not all the symbols in your layouts, which made everything a red mess. Removing that line solved for me.
EDIT: Seems like eclipse had the same problem early on.
In addition, make sure you do not have a drawable with an invalid name. I had a drawable with a numeric filename and that didn't sit well with Android so it failed to compile R.java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With