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

Shane McC
Shane McC
3,005 Points

Cannot be resolved or is not a field error?

When I created my new project, I set my minimium SDK version API to 14 (4.0 IceCreamSandwich). The Target API 19(4.4 KitKat). Compile API 19(4.4 KitKat).

In starting my project this way I'm getting the error "R cannot be resolved to variable". So I went ahead and fixed the issue by regenerating my R.java and BuildConfig.java files by going to Project->clean. My R.java and BuildConfig.java is now generated. My error "R cannot be resolved to variable" is now gone.

Here's my problem. When I add a new object, button, textview etc.. and try and set the contentview or findviewbyid to the object that I created in my XML file it's not finding it, I'm getting the error "splash cannot be resolved or is not a field"?

In order to find the item, I have to edit my R.java file (which is something I know I shouldn't do). After I do this and run the project on the emulator I'm getting an error

So here's my question, how do I get my id's to show up in the R.java file without having to manually edit it? How do I get rid of the "splash cannot be resolved or is not a field" error? without messing around with my R.java file?

Thanks

1 Answer

william parrish
william parrish
13,774 Points

When "R" populates in the autocomplete section of your code, you are sometimes presented with two options. R.android.whatever, and R.yourpackage.whatever.

Alot of times, if you inadvertently let it choose the stock android R field in intellisense / autocomplete, it wont be able to find the things you are trying to reference that you added yourself within your package. It will just have the generic built in stuff like the string "ok" etc.