2012年5月8日星期二

出现xxx cannot be resolved or is not a field问题的解决方案

这样的问题一般会在你的方法中引用resource中的场参数时出现,比如:

对于R.array有:array cannot be resolved or is not a field.
对于R.main有:main cannot be resolved or is not a field.
对于R.id有:id array cannot be resolved or is not a field.

要解决这个问题,首先看一下你的res文件夹中有没有这个场的定义,一般res中默认只有layout.main.xml, drawable.xxx和value.string.xml,需要自己添加一些你需要的xml文件。注意:一定要添加在恰当的位置比如说array.xml就应该在value这个文件夹下。

如果确认有,再检查一下res下面所有文件是否都无报错。如果res下某一个文件报错,比如main或者AndroidManifest,也会影响其他场不能正确被引用。

如果都没有错误,再检查一下在你的主程序中是否不小心引入了android.R如下:
import android.R
如果有,请删除。

如果还不行,可以尝试一下:Project ==> Clean ==> Check your project and press OK.

再不行的话,我也就没辙了。


2 条评论:

  1. 版主大大您好

    我出現的問題是
    对于R.main有:main cannot be resolved or is not a field.

    想請問我該如何檢查res文件夹中有没有这个场的定义?

    回复删除
    回复
    1. 你有可能需要用到res/layout/main.xml这个文件,可以先检查一下它是否存在

      删除