“id 无法解析或不是字段"错误? [英] "id cannot be resolved or is not a field" error?
本文介绍了“id 无法解析或不是字段"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不断收到此错误.我应该将 id
设为一个字段吗?
I keep getting this error. Should I just make id
a field?
我的代码是:
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
ImageView mainimage = (ImageView) findViewById(R.id.mainanim);
mainimage.setBackgroundResource(R.anim.mainanim);
mainanimation = (AnimationDrawable) mainimage.getBackground();
}
你是如何解决这个问题的?
How exactly do you fix this?
推荐答案
不要修改 R 类.该错误意味着您的 XML 布局存在语法错误,并且 R 无法自动生成.尝试查看并发布您不确定的 xml 代码(如果有).
Do not modify the R class. The error means there's something syntactically wrong with your XML layouts and R cannot be auto-generated. Try looking there and post the xml code you're not sure about, if any.
也:从文件顶部的导入中删除import android.R"(如果有)
Edit : also: remove "import android.R" from imports at top of file (if there)
这篇关于“id 无法解析或不是字段"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文