安卓:什么是R'为何如此隐秘? [英] Android: What is R? Why is it so Cryptic?

查看:192
本文介绍了安卓:什么是R'为何如此隐秘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图复制的记事本示例项目,这样,如果我鼓捣的源文件,以了解通过实验,原始样品文件将不会受到影响。

I have been trying to duplicate the NotePad sample project such that if I tinker with the source files in order to learn through experimentation, the original sample files will not be affected.

唉,尽管下面的<一个href="http://stackoverflow.com/questions/4928784/how-to-duplicate-an-sdk-sample-project-into-workspace">very清洁步骤在一个纯净的环境,研究开始反对我,<一个href="http://stackoverflow.com/questions/4577091/com-example-helloandroid-r-id-cannot-be-resolved">again!

Alas, despite following very clean steps in a pristine environment, R turned against me, again!

我得到了约20的研究不能被解析为一个变量错误...

I got about 20 "R cannot be resolved to a variable" errors...

现在,这就像抓22:我想学习记事本样本,让我有机会了解R是。但R不喜欢我这么多,所以它不给我研究的记事本样品的机会。

Now, this is like catch 22: I am trying to study the NotePad sample, so that I have a chance to understand what R is. But R doesn't like me so much, so it doesn't give me a chance to study the NotePad sample.

要雪上加霜的是,当我对谷歌的研究,我得到完全不相关的结果。

To add insult to injury, when I Google for R, I get totally irrelevant results.

  1. 什么是研究
  2. 为什么如此隐秘?
  3. 为什么永远是第一位的 解决不了?
  1. What is R?
  2. Why is it so Cryptic?
  3. Why is it always the first one that cannot be resolved?

更新:我注意到,在HelloAndroid项目(XML布局版本),有一个生成的Java文件,名为 R.java 。这是臭名昭著的研究关于该项目的建设者是抱怨?

Update: I noticed that in the HelloAndroid project (XML layout version), there is a generated Java file, named R.java. Is this the infamous R about which the project builder is complaining?

推荐答案

研究是包含在定义为特定的应用程序包中的所有资源类。它是在应用程序包的空间

R is a class containing the definitions for all resources of a particular application package. It is in the namespace of the application package.

例如,如果你在你的清单说你的包名为 com.foo.bar ,一个研究类与所有的资源的符号产生的 com.foo.bar.R

For example, if you say in your manifest your package name is com.foo.bar, an R class is generated with the symbols of all your resources in com.foo.bar.R.

有一般的两个 研究类,你会处理

There are generally two R classes you will deal with

  1. 框架资源 android.R
  2. 您自己的名称空间

它被命名为研究,因为这代表的研究物资跟不上,并且在让人们输入一些较长的,特别是因为它是没有任何意义共同结束了之后相当长的符号名称,可能会导致行包装一个公平的。

It is named R because that stands for Resources, and there is no point in making people type something longer, especially since it is common to end up with fairly long symbol names after it, that can cause a fair amount of line wrapper.

这篇关于安卓:什么是R'为何如此隐秘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆