R无法解决 - Android错误 [英] R cannot be resolved - Android error
问题描述
我刚刚下载并安装了新的Android SDK。
向导创建了这个代码:
package eu.mauriziopz.gps;
import android.app.Activity;
import android.os.Bundle;
public class ggps extends Activity {
/ **当活动首次创建时调用。 * /
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
但 Eclipse 给我的错误
R无法解决
<$> $ <$ p <$> c $ c> setContentView(R.layout.main);
为什么?
在
res / layout /
下有一个名为main.xml
的XML文件解决方案除了上面的答案中的建议,请确保您的Android目标已设置:
- 选择属性
- 在左侧菜单中选择Android
<
>编辑:一年后,我发现另一个原因。我在我的drawable文件夹中有一个.jpg图像与.png图像同名。在我的代码中引用此图像必须混淆程序,它给出了R无法解决的错误。
I just downloaded and installed the new Android SDK. I wanted to create a simple application to test drive it.
The wizard created this code:
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); } }
but Eclipse gives me the error
R cannot be resolved
on line
setContentView(R.layout.main);
Why?
PS: I do have an XML file named
main.xml
underres/layout/
.解决方案Along with the great suggestions in the previous answers, make sure your Android target is set:
- 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
Edit: 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屋!