我为一个 Activity 编写了简单的 android 代码,并通过布局文件夹中名为 second.xml 的 xml 文件提供了它的 View 。我也在 mainfiest 文件中提到了这个 Activity 。但我面临着“第二个不能是”的错误在 setContentView 方法中解决或它不是一个字段”。 请给出解决方案
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class Second extends Activity
{
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
// Intent i=getIntent();
}
}
最佳答案
你只需要从 Project->Clean 中清理你的项目,并在清理它之前从 Second 中删除 import android.R;。确保你有 second.xml src/layout/second.xml 下的文件。
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class Second extends Activity
{
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
// Intent i=getIntent();
}
}
关于android - id无法解析或不是字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10878178/