问题描述
我有一个应用程序分为子包,仅用于个人组织:
I have an application divided in subpackages, just for personal organization:
com.myname.myapp
|
`- com.myname.myapp.activities
|
`- com.myname.myapp.whatever
|
`- ...
问题是生成的 R.java 位于 com.myname.myapp
,因此当我在子包中的类中键入 R.id.something
时com.myname.myapp.activities
,我得到 R 无法解析为变量
(我猜很明显).
The problem is that the generated R.java is located at com.myname.myapp
and thus when I type R.id.something
in a class from the subpackage com.myname.myapp.activities
, I get R cannot be resolved to a variable
(obvious I guess).
当我点击 Organize imports (Ctrl+Shift+O) 时,Eclipse 修复它,在顶部添加 import com.myname.myapp.R
,一切看起来完美地工作.但另一方面,Android 文档 指出:
When I click on Organize imports (Ctrl+Shift+O), Eclipse fixes it adding import com.myname.myapp.R
at the top, and everything seems to work perfectly. But on the other hand, Android documentation states this:
Eclipse 有时喜欢在使用资源的文件顶部添加 import android.R 语句,尤其是当您要求 eclipse 对导入进行排序或以其他方式管理导入时.这将导致您的制造中断.注意这些错误的导入语句并删除它们
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
知道一切正常,我该怎么办?
Knowing that everything is working perfectly, what should I do?
推荐答案
你可以在任何你想要的地方导入 R.file.
You can import R.file where ever you want.
import com.myname.myapp.R;
或者像这样在变量处使用
or else use at the variable like this
com.myname.myapp.R.id.test
这篇关于从不同的包访问 R.java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!