Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Android Lists and Adapters (2015) Lists with RecyclerViews Introducing RecyclerView

Stephen Little
Stephen Little
8,312 Points

can 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

Stephen Little
Stephen Little
8,312 Points

I didn't do anything and the problem went away all on it's one? Not sure what is going on here, any thoughts?

4 Answers

Abhinav Kanoria
Abhinav Kanoria
7,730 Points

This 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

Variables in "R." are compiled. It is possible that your project had not yet compiled and android studio did not recognize the reference yet.

I'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
Andres Badilla
4,692 Points

This 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"