Android R文件丢失或R cannot be resolved to a variable
来源:互联网 发布:搭建php开发环境 编辑:程序博客网 时间:2024/06/07 00:28
写Android遇到了R cannot be resolved to a variable的问题,查看gen目录,没看到R文件,以前没遇到过,一时间解决不了问题,还好网上有博主写了一个解决方法刚好就是属于我遇到的问题。在这里也写一篇博文,权当为其他遇到这个问题的同学一个借鉴吧。
导致R cannot be resolved to a variable或者找不到id的可能原因有:
1)原因:import的是系统自带的android.R,
解决方法:删掉这句import android.R;,导入你自己项目的R,比如 import com.example.myproject.R;
2)原因:你的xml文件存在错误,而你又不小心按了run,然后又clean,build了一下项目,结果R文件又是对着你的xml文件生成的,导致R文件没有生成,gen缺失R文件
解决方法:
clean项目,查看Console中的红色错误报告,fix这个报告中涉及的xml文件的错误,然后再生成就可以生成R文件了
3)原因:其实这个可以说是总的原因了,res目录下存在错误,R文件都不会生成,比如你用了大写字母了命名你需要用到的图标
解决方法;
同样clean项目,查看Console中的错误报告,对症下药,解决res目录中的错误
最后附上解决了我问题的博主的链接致敬:
http://www.cnblogs.com/leizhenzi/archive/2011/07/30/2121824.html#commentform
0 0
- Android R文件丢失或R cannot be resolved to a variable
- R cannot be resolved to a variable
- r cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- R cannot be resolved to a variable
- 51nod 1422:沙拉酱前缀
- 数列求和
- 媒体服务器性能评估必须考虑的几个指标
- 【bzoj3196】【坑】Tyvj 1730 二逼平衡树 线段树套Treap/Splay
- Java RMI学习
- Android R文件丢失或R cannot be resolved to a variable
- openjudge 切割回文
- 用conda管理Python包
- 二叉树的创建与遍历
- makefile简单编写
- Css和Jquery的一些学习认识(一)
- 错误:App Transport Security has blocked a cleartext HTTP...
- VS常用快捷键,真的是常用
- 关于实现自定义浏览器框架的相关细节问题