进口android.R在Eclipse:为什么呢? [英] import android.R in Eclipse : Why?

查看:158
本文介绍了进口android.R在Eclipse:为什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档的摘录:

Eclipse中有时喜欢在增加一个进口android.R声明   您的文件使用的资源,尤其是当你问Eclipse之上   排序或以其他方式管理进口。这将导致你的化妆来   打破。寻找出这些错误的import语句,并删除它们。

Eclipse sometimes likes to add an import android.R statement at the top of your files that use resources, especially when you ask eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import statements and delete them.

我的问题:??为什么为什么日食继续做这个

My question : WHY? Why does eclipse keep on doing this?

我一直在开发使用Eclipse的一个相当长的一段时间,现在的Andr​​oid应用程序,但我从来没有能够理解为什么月食做这样的事情。

I have been developing Android applications using Eclipse for a quite some time now but I have never been able to understand why eclipse does such a thing.

当我使用<大骨节病>控制 + <大骨节病>移 + <大骨节病> 0 组织我import语句, 进口机器人。 - [R 被自动添加。而突然间我正确的code突然浑身红色错误,说的研究解决不了。它可以得到真正可怕的初学者,因为他不知道他做了什么错。

When I use Ctrl + Shift + O to organize my import statements, import android.R gets added automatically. And all of a sudden my correct code is suddenly covered in red errors, saying that R cannot be resolved. It can get really scary for a beginner as he has no idea what he did wrong.

在另一种情况下,假设有什么毛病我的布局文件和 R.java 不被产生,它说,研究解决不了,因为R.java尚未因错误产生。当我将我的光标移动到任何错误,它表明我进口android.R

In another scenario, suppose there is something wrong with my layout files and R.java is not being generated, it says that R cannot be resolved, as R.java has not been generated due to the errors. As I move my cursor to any of the errors, it suggests me to import android.R.

工作在Android上相当一段时间了,我知道,永远导入android.R,但我从来没有能够理解为什么月食不断暗示它,因为坦白说,加进口android.R从来没有解决我的任何问题。它只是添加到现有的问题,这曾经是在开发的最初几天真的很痛苦。

After working on Android for quite sometime now, I know that never to import android.R, but what I have never been able to understand why eclipse keeps on suggesting it, as frankly speaking, adding import android.R never solved any problem of mine. It just added to the existing problems, which used to be really painful during initial days of development.

所以,没有人知道背后蚀使建议作出不正确进口的原因是什么?难道仅仅是一个错误?我不认为这是一个错误,因为它会得到固定的有人提到对Android文件后至少。

So, does anyone know the reason behind eclipse making the suggestion to make an incorrect import? Is it just a bug? I don't think it's a bug, as it would have got fixed at least after it was mentioned on the Android documentation.

如果这不是一个错误,那么什么是真正的目的 android.R ?这是什么究竟是指什么?

If it's not a bug, then what is a real purpose of android.R? What does it exactly refer to?

您的意见/经验,将是非常有帮助的!

Your opinions/experiences will be really helpful!

谢谢!

推荐答案

这是不是一个错误。有一些情况下 android.R 可以帮助解决问题。

This is not a bug. There are a few instances where android.R can be helpful and solve problems.

android.R 是一个R.java文件中像一个你在自己的项目。一个在您的项目( your.packagename.R )持有引用你在你的 / RES 文件夹中的资源喜欢的布局,可绘,XML文件,原始文件,字符串等。

android.R is an R.java file like the one you have in your own projects. The one in your projects (your.packagename.R) holds references to the resources you have under your /res folder like layouts, drawables, XML files, raw files, strings etc.

在另一方面,在 android.R 文件包含引用某些默认资源Android有内置,像 simple_list_item_1管理

On the other hand, the android.R file holds references to certain default resources that Android has inbuilt, like simple_list_item_1.

Eclipse中表明,这和汽车进口这种有时,如果你的项目的R档还未产生,由于XML错误什么的,你的code将引用不存在的文件。通过导入 android.R ,月食可以确保你的code引用了一个真实存在的类。然而, android.R 不太可能你做同样的资源,而这将引发另一组错误的。

Eclipse suggests this and auto imports this sometimes as if your project's R file hasn't been generated due to an XML error or something, your code will be referencing a file that doesn't exist. By importing android.R, eclipse makes sure your code references a class that exists. However, android.R is unlikely to have the same resources you did, and this will raise another set of errors.

这篇关于进口android.R在Eclipse:为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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