5

I am trying to understand Android TCP client and Server communication, illustrated here and errs here. I get all the time "R cannot be resolved to a variable" and it is used like the below. What is this R -object that has methods such as layout and id?

setContentView(R.layout.main);
textDisplay = (TextView) this.findViewById(R.id.text1);

P.s. You can find the codes in GitHub tcpcommclient and tcpcommserver here.

hhh
  • 50,788
  • 62
  • 179
  • 282
  • possible duplicate of [Understand the R class in Android](http://stackoverflow.com/questions/6804053/understand-the-r-class-in-android) – Dharmendra Nov 04 '12 at 04:32

1 Answers1

10

R is a static class that lists all your resources (usually defined in XML, but all available in your res folder).

For more info: Understand the R class in Android

edit: According to here: The android java class cannot recognize the R file one of your classes might actually be importing the R.java class. Never do that. If there are imports of that class, remove them.

Also, You might to clean the project (project - clean - clean project)

Community
  • 1
  • 1
ajacian81
  • 7,419
  • 9
  • 51
  • 64
  • ...can you say how to solve this undefined problem? It is automatically-generated so how can I initialize it in eclipse? – hhh Nov 03 '12 at 21:56
  • 1
    Try to clean your project and build again. – ajacian81 Nov 03 '12 at 21:59
  • I don't know yet what I should do in Eclipse -- anyway trying and copying them again to new projcet -- I downloaded the codes [here](http://koti.kapsi.fi/~he/multicastMe.tgz). – hhh Nov 03 '12 at 22:02
  • Updated with 2 suggestions including link to similar question. – ajacian81 Nov 03 '12 at 22:09
  • I removed the generated R -thing in trying to clean things, now I am not sure how I can get it back. Ideas? Sorry I am a bit jammed. – hhh Nov 03 '12 at 22:10
  • Clean your project, it should be generated then: Procject menu -> clean -> clean project. – ajacian81 Nov 03 '12 at 22:16
  • 1
    If it is not generated, you might have an error in one of your resource files. Fix that and R.java should be generated. – nhaarman Nov 03 '12 at 22:24
  • 1
    Thank you, I fixed the problem by using default import -features. In copy-pasting, it is easy to mess up things. – hhh Nov 03 '12 at 23:26