xxx cannot be resolved or is not a field
2014-06-27 15:34
417 查看
参考文章:http://stackoverflow.com/questions/3296047/id-cannot-be-resolved-or-is-not-a-field-error
【1】Look at your
at the top. If you are saying
如果有android.R,则删去import android.R。
【2】If that doesn't fix it, make sure your eclipse plugin(ADT) and your android SDK are fully up to date, remove the project from the emulator/phone by manually deleting it from the OS, and clean the project (Launch Eclipse->Project->Clean...). Sounds silly
to make sure your stuff is fully up to date, but the earlier versions of the ADT and SDK has a lot of annoying bugs related to the R files that have since been cleared up.
确认Build Automatically,再试试Launch Eclipse->Project->Clean。
【3】Just FYI, the stuff that shows up in the R class is generated from the stuff in your project res (aka resources) folder. The R class allows you to reference a resource (such as an image or a string) without having to do file operations all over the place.
It does other stuff too, but that's for another answer. Android OS uses a similar scheme - it has a resources folder and the class android.R is the way to access stuff in the android resources folder. The problem arises when in a single class you are using
both your own resources, and standard android resources. Normally you can say
the top, and then reference a class just using the last bit of the name (for example,
your class and the compiler knows you mean
When you need to use two classes that are named the same thing, as is the case with the auto-generated R class, then you can import one of them and you have to fully qualify the other one whenever you want to mean it. Typically I import the R file for my project,
and then just say android.R.whatever when I want an android resource.
Also, to reiterate Andy, don't modify the R file automatically. That's not how it's meant to be used.
最后试试File->Refresh和File->Save。
确保语法没有错误。
【1】Look at your
importstatements
at the top. If you are saying
import android.R, then there that is a problem. It might not be the only one as these 'R' errors can be tricky, but it would definitely definitely at least part of the problem.
如果有android.R,则删去import android.R。
【2】If that doesn't fix it, make sure your eclipse plugin(ADT) and your android SDK are fully up to date, remove the project from the emulator/phone by manually deleting it from the OS, and clean the project (Launch Eclipse->Project->Clean...). Sounds silly
to make sure your stuff is fully up to date, but the earlier versions of the ADT and SDK has a lot of annoying bugs related to the R files that have since been cleared up.
确认Build Automatically,再试试Launch Eclipse->Project->Clean。
【3】Just FYI, the stuff that shows up in the R class is generated from the stuff in your project res (aka resources) folder. The R class allows you to reference a resource (such as an image or a string) without having to do file operations all over the place.
It does other stuff too, but that's for another answer. Android OS uses a similar scheme - it has a resources folder and the class android.R is the way to access stuff in the android resources folder. The problem arises when in a single class you are using
both your own resources, and standard android resources. Normally you can say
importat
the top, and then reference a class just using the last bit of the name (for example,
import java.util.Listallows you to just write
Listin
your class and the compiler knows you mean
java.util.List).
When you need to use two classes that are named the same thing, as is the case with the auto-generated R class, then you can import one of them and you have to fully qualify the other one whenever you want to mean it. Typically I import the R file for my project,
and then just say android.R.whatever when I want an android resource.
Also, to reiterate Andy, don't modify the R file automatically. That's not how it's meant to be used.
最后试试File->Refresh和File->Save。
确保语法没有错误。
相关文章推荐
- xxx 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
- R.layout.xxx cannot be resolved or is not a field问题解决办法
- 添加jar包编译出现错误"XXX cannot be resolved or is not a field"解决方法
- Eclipse Android项目 为控件添加了Id,但是在Java代码中提示xxx cannot be resolved or is not a field
- xxx cannot be resolved or is not a field
- Eclipse Android项目 为控件添加了Id,但是在Java代码中提示xxx cannot be resolved or is not a field
- 关于id cannot be resolved or is not a field 的一个解决方法
- "cannot be resolved or is not a field"问题解决
- styleable cannot be resolved or is not a field
- result cannot be resolved or is not a field
- Android中cannot be resolved or is not a field错误的解决办法
- 在android编程中出现cannot be resolved or is not a field
- R.xml.preference报错:preference cannot be resolved or is not a field
- "cannot be resolved or is not a field"问题解决
- eclipse中system.out.println()出现问题,总是提示out cannot be resolved or is not a field
- main cannot be resolved or is not a field
- Android Error:main cannot be resolved or is not a field,异常语句:setContentView(R.layout.main);
- xml cannot be resolved or is not a field