【android調試】R cannot be resolved to a variable

原文地址:http://blog.sina.com.cn/s/blog_8a94d82b0101bdfb.html
真是奇怪,第一次導入一個項目時,竟然沒有產生R.java文件,結果程序中一大堆錯誤,全是R cannot be resolved to a variable。

結果上網搜了半天,結果是

第一個查到的方法:

很多人碰到創建新工程的時候出現 cannot be resolved to a variable的問題時沒法在第一時間得到最好的解決

其根本原因是r.java文件沒有自動生成

關於一般的解決方案在網上很多人提出來了

比如CLEAN工程,CLEAN UP RESOURCE,Android Tools >> Fix Project Properties 等

但還是部分人看了網上的帖還不能解決,那麼請注意兩點:

1. 如果你在更新下載SDK,那麼先關閉,重啓ECLIPSE便可

2. 如果還不行,則更新完整ADT、SDK

本文出自 “清風柳絮” 博客,請務必保留此出處http://binuu.blog.51cto.com/801317/775781

第二個查到的方法:

*Note: 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.*

While going through the Android sample tutorials, I would often use the Ctrl + Shift + O command to "Organize Imports" and generate any missing import statements. Sometimes this would generate the incorrect import statement which would hide the R.java class that is automatically generated when you build.

自我感覺應該是生成R.java的過程被打斷了或發生了意外,於是刪除原來的項目,重新導入,

哦哦,這次真的就成了!自動產生了R.java文件。呵呵

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章