Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android & Java: what is the odd object called `R`?

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.

like image 527
hhh Avatar asked Nov 03 '12 21:11

hhh


People also ask

What OS does Android use?

Android OS is a Linux-based mobile operating system that primarily runs on smartphones and tablets. The Android platform includes an operating system based upon the Linux kernel, a GUI, a web browser and end-user applications that can be downloaded.

Is Android good or Apple?

Whether iOS is better than Android in security is now up for debate, but the consensus still gives Apple the upper hand. iOS has more consistent updates for all devices, a closed ecosystem that is harder to penetrate, and a stricter app store.

Is Android only for Samsung?

Samsung is just one manufacturer that uses Android. Others include Sony, Motorola, LG, OnePlus, and Huawei. But while all of these manufacturers use Android on their phones, that doesn't mean the experience is the same on all of them. This goes back to the open-source nature of Android.


1 Answers

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)

like image 187
ajacian81 Avatar answered Sep 26 '22 12:09

ajacian81