問題描述
我有一個應(yīng)用程序分為子包,僅用于個人組織:
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
,因此當(dāng)我在子包中的類中鍵入 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).
當(dāng)我點擊 Organize imports (Ctrl+Shift+O) 時,Eclipse 修復(fù)它,在頂部添加 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 語句,尤其是當(dāng)您要求 eclipse 對導(dǎo)入進(jìn)行排序或以其他方式管理導(dǎo)入時.這將導(dǎo)致您的制造中斷.注意這些錯誤的導(dǎo)入語句并刪除它們
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?
推薦答案
你可以在任何你想要的地方導(dǎo)入 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
這篇關(guān)于從不同的包訪問 R.java的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!