Android中cannot be resolved or is not a field错误的解决办法
2016-11-12 22:20
519 查看
以下问题可以参考:
1.R cannot be resolved or is not a field
2.id cannot be resolved or is not a field
在写第一程序的时候,遇到了这个错误,我在引用一个变量时,ListView myListView = (ListView)findViewById(R.id.myListView);
总是提示我这个错误,但是我仔细检查了layout文件中我已经写的就是这个id.
然后我试着import R,这时候R下面又提示这个错误了
于是我把import这一句删除了(1.R cannot be resolved or is not a field的解决方法)
在网上大致搜索了一下,大家给出的意见就是没有保存好layout没有生成R文件
于是我多次保存但还是不行,
这时候我发现自己res/menu/下的文件也有提示错误,打开后发现是Android:title引用了string文件中一个我刚刚删除的变量,
把这个引用改成输入一个字符串或者在res/values/string文件下添加这个引用
这时候再去给layout文件加一个空格什么的重新保存一下,R文件就会生成了.
总的来说,出现问题2的原因就是R文件没有生成,或者更改后没有生成好,自习检查自己的代码后,再去查找其他文件中有没有错误,所有文件没有错误,R文件才可以自动生成
----------------分割线------------------
补充:大多时候,是资源文件出现错误,有时候eclipse就不会报错,但是你clean后,因为项目有错误,R文件就消失了。
例如:drawable中的图片文件,不能有大写等
1.R cannot be resolved or is not a field
2.id cannot be resolved or is not a field
在写第一程序的时候,遇到了这个错误,我在引用一个变量时,ListView myListView = (ListView)findViewById(R.id.myListView);
总是提示我这个错误,但是我仔细检查了layout文件中我已经写的就是这个id.
然后我试着import R,这时候R下面又提示这个错误了
于是我把import这一句删除了(1.R cannot be resolved or is not a field的解决方法)
在网上大致搜索了一下,大家给出的意见就是没有保存好layout没有生成R文件
于是我多次保存但还是不行,
这时候我发现自己res/menu/下的文件也有提示错误,打开后发现是Android:title引用了string文件中一个我刚刚删除的变量,
把这个引用改成输入一个字符串或者在res/values/string文件下添加这个引用
这时候再去给layout文件加一个空格什么的重新保存一下,R文件就会生成了.
总的来说,出现问题2的原因就是R文件没有生成,或者更改后没有生成好,自习检查自己的代码后,再去查找其他文件中有没有错误,所有文件没有错误,R文件才可以自动生成
----------------分割线------------------
补充:大多时候,是资源文件出现错误,有时候eclipse就不会报错,但是你clean后,因为项目有错误,R文件就消失了。
例如:drawable中的图片文件,不能有大写等
相关文章推荐
- Android中cannot be resolved or is not a field错误的解决办法
- 关于"cannot be resolved or is not a field"错误的解决方法
- Andrion错误解决:cannot be resolved or is not a field
- irectory_list cannot be resolved or is not a field问题的解决办法
- android的菜单错误:add cannot be resolved or is not a field
- 出现"cannot be resolved or is not a field"莫名错误的解决方法
- android中如何解决“main cannot be resolved or is not a field”
- "activity_main cannot be resolved or is not a field"的解决办法
- 添加jar包编译出现错误"XXX cannot be resolved or is not a field"解决方法
- R.layout.xxx cannot be resolved or is not a field问题解决办法
- Android Error:main cannot be resolved or is not a field 问题解决方法
- "cannot be resolved or is not a field"问题解决
- "cannot be resolved or is not a field"问题解决
- "cannot be resolved or is not a field"问题解决
- 解决 cannot be resolved or is not a field
- 关于id cannot be resolved or is not a field 的一个解决方法
- Eclipse Android项目 为控件添加了Id,但是在Java代码中提示xxx cannot be resolved or is not a field
- Android Error:main cannot be resolved or is not a field,异常语句:setContentView(R.layout.main);