R.layout.main cannot be resolved

来源:互联网 发布:本溪 农业 盘古网络 编辑:程序博客网 时间:2024/05/20 06:41

R.layout.main cannot be resolved



刚写了一行就出了这么个错误,让我很郁闷。。

找了大半天,最后才发现

在最开始 ,不知道什么时候

import android.R;


解决方案:

删除第三行的“import android.R” 注:我不知道是什么时候加进来的。


原因分析:

删除“import andorid R”之后工程就是从/res文件夹下自动生成的资源空间里去解析了,否则它会从Android的资源类里去找。


Openstask上的回答是:


After tracking down this problem as well, I found this note in the Android documentation:

http://source.android.com/source/using-eclipse.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 yourmake 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 theR.java class that is automatically generated when you build.