• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eclipse: "R cannot be resolved to a variable" in Android code

 
waqas imtiaz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have installed eclipse and followed steps by installing the install new software and setting up sdk as well. removed android.R import, added com.home.begingwithandroid.R import but still nothing works for me. Please help me on this.

Thanks.
 
Paul Clapham
Sheriff
Posts: 21559
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I guess that you're referring to some Java code? If so, then could you post that code so we could see it? If not, then maybe you could clarify your question by providing more details?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "nothing works for me" mean? If there are error messages, post them. Also tell us whether you want to refer to something in android.R, or your own app's R class. If the latter, is your main package really "com.home.begingwithandroid"? That "g" is suspicious; is that a typo? Furthermore, tell us what specific element you're trying to refer to, and in which way you think you have have defined it. Also tell us in which package the class is that causes the problem. In short, as Paul said: TellTheDetails

@Paul: The "R" class is an Android-specific class that gets created automatically by the compiler. So the rules of importing and using it are not quite the same as for "normal" Java classes.
 
waqas imtiaz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is the code of the problem.




here 'R' is the problem.
With 'R' it gives following error:

"R cannot be resolved to a variable"

Does this clear the scenario? Please tell me if more explanation is required.
 
waqas imtiaz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean I have tried to search over the internet to fix this problem but nothing has worked for me.

Well, I am new, I have just installed eclipse and tried to run this code written in book but this error pops up. I do not know what is "android.R or what is my own app's R class" as I am new to it.

Please help me on this
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your code it's clear you're trying to use your own package's R class, not Android's. That gets us back to:

is your main package really "com.home.begingwithandroid"? That "g" is suspicious; is that a typo?


The main package is set in the AndroidManifest.xml file; what is it?
 
waqas imtiaz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:From your code it's clear you're trying to use your own package's R class, not Android's. That gets us back to:

is your main package really "com.home.begingwithandroid"? That "g" is suspicious; is that a typo?


The main package is set in the AndroidManifest.xml file; what is it?


Package from AndroidManifest.xml is:

package="com.home.begingwithandroid"
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks correct. I suspect something is wrong with the Eclipse Android setup, so I'll add this discussion to the IDE forum as well.
 
waqas imtiaz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:That looks correct. I suspect something is wrong with the Eclipse Android setup, so I'll add this discussion to the IDE forum as well.


So what should I do untill it is fixed?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google for answers, and tinker around with your Eclipse project. It's not a given that will get a solution here quickly (or ever, actually), so you should have a backup plan how to solve this.
 
waqas imtiaz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Google for answers, and tinker around with your Eclipse project. It's not a given that will get a solution here quickly (or ever, actually), so you should have a backup plan how to solve this.


Alright
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic