setContentView 设置布局文件时,cannot be resolved or is not a field
来源:互联网 发布:origin点显示数据 编辑:程序博客网 时间:2024/06/02 23:51
最近在用setContentView()设置Activity的布局文件时,会报错,如“weather_layout cannot be resolved or is not a field”,导致在使用findViewById()获取xml文件中的控件时,也会报错,如“city_name cannot be resolved or is not a field”,具体代码见附图。
解决方法:
1.检查setContentView()使用的layout目录下的xml文件字是否拼写有误,附图中的weather_layout对应layout目录下的weather_layout.xml对应,正确无误。
2.检查导入的R文件。R.java文件是由aapt工具根据res中的资源自动生成的,通过R.java文件可以对资源进行索引,该文件不能进行手动修改。最容易犯的错误是导入错误的R文件“android.R”,该R是java.lang.Object的子类。正确的R文件应当是“ 包名.R”,包名可以在AndroidManifest.xml 中 package一项得到。因而,本例正确代码”import com.coolweather.app.R”,而不是“import android.R”。快捷的做法是删掉“import android.R”单击红叉,选择 import “R”(包名),通常是第二条。
0 0
- setContentView 设置布局文件时,cannot be resolved or is not a field
- main cannot be resolved or is not a field
- main cannot be resolved or is not a field
- layout cannot be resolved or is not a field
- main cannot be resolved or is not a field
- main cannot be resolved or is not a field
- main cannot be resolved or is not a field
- (Layout) cannot be resolved or is not a field 错误
- main cannot be resolved or is not a field
- button1 cannot be resolved or is not a field
- "cannot be resolved or is not a field"问题解决
- main cannot be resolved or is not a field错误
- R.xxx cannot be resolved or is not a field
- XXX cannot be resolved or is not a field
- xml cannot be resolved or is not a field
- TYPE_LINEAR_ACCELERATION cannot be resolved or is not a field
- xxx cannot be resolved or is not a field
- Type activity_main cannot be resolved or is not a field
- 一件程序猿T恤的故事
- [POJ_1054]LETTERS
- MathType中关于平行且相等符号的编辑方法
- arcgis server发布时遇到的问题
- D3+mysql 画Force图
- setContentView 设置布局文件时,cannot be resolved or is not a field
- notepad++多行标签设置方法
- Notepad++输入模式之修改模式、插入模式
- ruby redis使用
- Linux strsep() 用法
- 2012年5月SAT香港真题解析
- 3.创建一个20个大小的随机数组,找出这组数组的最大值和最小值, 并且标出最大数和最小值的位置
- 利用Dummynet模拟恶劣网络环境
- 表格布局