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
Holly Fox
2,808 PointsCannot resolve symbol R when hooking up the layout files
This has been a problem before but it resolved itself without me understanding what the problem was.
I have wrote my java code which has been running fine. I've now been making amendments to the layout file. I have only changed positioning of elements and haven't made any changes to ID's etc.
But now, for no particular reason, I have an error in my java code saying cannot resolve R for the following code:
setContentView(R.layout.activity_colour_mix);
I've tried rebuilding and cleaning but it won't let me. I've tried ctrl + space after setContentView to force an import but thats not working either.
Any ideas?
1 Answer
Holly Fox
2,808 PointsThe problem has resolved!
This time it was a problem in my layout file. I had 3 elements; I aligned the middle element with the center of the screen and aligned the other 2 above and below. Although there weren't any errors showing, as soon as I adjusted the code for the way this was aligned (aligning now based on the parent), android allowed me to clean and rebuild and the errors went away.
Its a bit frustrating that the layout file didn't show the source of the error but it does seem to be the problem.