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 Build a Simple Android App (retired 2014) Getting Started with Android Android Setup and the Crystal Ball Project

Johan Nurmilehto
Johan Nurmilehto
860 Points

MainActivity.java

Whenever I start up a new android project I get two errors in MainActivity. Those are that R cannot be resolved to a variable (so I import android.r) but now I get and error saying that main cannot be resolved or is not a field.

Im stuck and have no clue what the problem is.

3 Answers

Hi, do you have more than one activity? In the eclipse errors section is there more than one error? The R build file will always error if there are errors elsewhere in your code. A good way to check this is to "clean" your projects. (In eclipse, under the project menu item, click "clean". This will rebuild and reassociate any cached relationships between files. Then you will hopefully see what the real error is. It would help to post the code you are having issues with. Look at the "Markdown Cheatsheet" link below the comment box to see how to easily paste formatted code!

Johan Nurmilehto
Johan Nurmilehto
860 Points

I had just one activity and those two errors I mentioned, the weird thing was that I got those errors on startup. So I didn't write a single line of code myself. I also tried clean with no luck so I just gave up and reinstalled eclipse and the plugins and now its working. Computers huh

Ah, ok, glad you got that sorted! Yeah they can be as moody as teenagers sometimes :)