R无法解决 - Android错误 [英] R cannot be resolved - Android error
问题描述
我刚刚下载并安装了新的Android SDK。我想创建一个简单的应用程序来测试驱动器。
I just downloaded and installed the new Android SDK. I wanted to create a simple application to test drive it.
向导创建了此代码:
package eu.mauriziopz.gps;
import android.app.Activity;
import android.os.Bundle;
public class ggps extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
但 Eclipse 给了我错误
R无法解决
R cannot be resolved
在线
setContentView(R.layout.main);
为什么?
PS:在 res / layout /
下有一个名为 main.xml
的XML文件。
PS: I do have an XML file named main.xml
under res/layout/
.
推荐答案
除了以前的答案中的很好的建议,请确保您的Android目标设置为:
Along with the great suggestions in the previous answers, make sure your Android target is set:
- 右键单击您的项目
- 选择属性
- 在左侧菜单中选择Android
- 单击应用并确定
<单击相应的项目构建目标旁边的框。
- Right-click on your project
- Choose Properties
- Choose Android in the left menu
- Tick a box next to the appropriate Project Build Target.
- Click Apply and OK
编辑:一年后,我发现了另一个原因。我的drawable文件夹中的.jpg图像与.png图像的名称相同。在我的代码中引用此图像必须使程序混淆,并给出R无法解决错误。
A year later I found another cause. I had a .jpg image in my drawable folder with the same name as a .png image. Referencing this image in my code must have confused the program and it gave the "R cannot be resolved" error.
这篇关于R无法解决 - Android错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!