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 trial

Android

Help with SetContentView() R cannot be resolved to variable

I could really use some help, I can't find a solution anywhere on the internet for my problem, I've been working on a project and when I loaded it today for each of the activities I have SetContentView(R.layout.mainScreen); The R is underlined in red and it says "R cannot be resolved to variable" What can I do to fix this? I would appreciate some help so much! Thank you

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hi Matt, files in the res directory (where the R class gets generated from) cannot have uppercase letters. Change your layout filename to main_screen and you should fix these errors. This is a weird rule that I think every Android developer runs into when first starting!