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 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 :)