Nict
Nict

Reputation: 3098

Known issue: "R cannot be resolved to a variable"

When I first started android app development I was following the developer.android.com course, and the first error I stumbled upon was the famous "R cannot be resolved to a variable".

I've been looking all around for this issue, I cleaned my projects multiple times, but to no certain avail. I was thinking maybe it has something to do with the version of Java, as the android sdk only seems to be more stable with Java 1.6.

What I haven't figured out is how to actually resolve the issue completely, as I would love to use switch on my String.

edit:
I wrote an answer to this as well. Hope this will help some unfortunate people out there.

Upvotes: 1

Views: 121

Answers (3)

Stephen C
Stephen C

Reputation: 718768

What I haven't figured out is how to actually resolve the issue completely, as I would love to use switch on my String.

If you are developing code for Android, you cannot use "switch on String" or other Java 7 language features. Android's Java language is Java 6.


As for the generic "R cannot be resolved ..." problem, there are lots of possible causes. I suggest you start by trawling through the possibilities listed here: "R cannot be resolved to a variable"?

Upvotes: 1

Vitor Venturin
Vitor Venturin

Reputation: 1289

This is a nightmare. I've been through that many times. One solution I found was switch between Eclipse's workspaces and import the project again. Sometimes works, sometimes not. :/ Regards

Upvotes: 0

Nict
Nict

Reputation: 3098

Having jre/jdk 1.7 loaded in your eclipse development environment seems to *usually resolve the issue.
If this is a know answer, I'm in the dark, because I've been looking around for exactly this.

To fix it, you simply load in 1.6 (which again makes you unable to switch on String-types), or right-click on your project in your Package Explorer -> Android Tools -> Fix Project Properties...

Your "R cannot be resolved" error will disappear, but beware if you're using any 1.7-introduced functionalities.

  • Keep in mind that there are multiple other answers out there and I recommend you to keep googling or reading StackOverflow for more answers, but this was just my .2 milles.

Upvotes: 0

Related Questions