Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialStephen Little
8,312 Pointscan not resolve symbol R coming up now, how to fix
for some reason I am getting this error and all the R's are red.... I'll put one line down to show you what I mean. It's not just this one line of all lines with the R value in it..
Toast.makeText(this, getString(R.string.network_unavailable_message)
The R is red and give the error "Can not resolve symbol" any thoughts?
Cheers! Stephen
4 Answers
Abhinav Kanoria
7,730 PointsThis happens many a times while building android projects. When you first create a new class or new activity and Android Studio says it can't recognize symbol R, probably you can hover over the R symbol, hit Alt+Enter and choose import class from the drop down menu. The appropriate file will be imported for you. Also, it is recommended to clean up your project from time to time. Sometimes there are 'errors' which seem to be errors but aren't really errors.Once you clean your project, the 'errors' are gone! You can clean your project by selecting Build > Clean Project
jason phillips
18,131 PointsVariables in "R." are compiled. It is possible that your project had not yet compiled and android studio did not recognize the reference yet.
James Lowry
7,975 PointsI'm having a similar issue. I attempted to rebuild and clean the project. I was thinking all I needed to do was this and it would fix it like normal. Now it isn't going away... Even the import statement has the red R.
import teamtreehouse.com.stormy.R;
If I hover over top of the import statement it states 'unused import statement'. I'm going to restart Android Studio and see if this fixes it(while I take the quiz).
Edit: Restart didn't fix
Andres Badilla
4,692 PointsThis is caused because you can't build your project. The same issue happened to me and this is what I did:
on the "build.gradle", add the recyclerview dependency as follows:
compile 'com.android.support:recyclerview-v7:21.0.+'
and then change the minSdkVersion and the targetSdkVersion fields on the same file (build.gradle) to 21 so it matches the version of recyclerview we are using:
minSdkVersion 21
targetSdkVersion 21
Finally remember to sync your gradle files and it should complete successfully.
NOTE If you are still getting this error after following these steps, rebuild your project by going to "Build" in the menu bar and the click on "Rebuild project"
Stephen Little
8,312 PointsStephen Little
8,312 PointsI didn't do anything and the problem went away all on it's one? Not sure what is going on here, any thoughts?