您的位置:首页 > 移动开发 > Android开发

【android调试】R cannot be resolved to a variable

2015-04-21 23:33 405 查看
原文地址: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
本文出自 “清风柳絮” 博客,请务必保留此出处/article/6944646.html

第二个查到的方法:

*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文件。呵呵
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: