R无法解决 - Android错误 [英] R cannot be resolved - Android error

查看:299
本文介绍了R无法解决 - Android错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚下载并安装了新的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:


  1. 右键单击您的项目

  2. 选择属性

  3. 在左侧菜单中选择Android

  4. <单击相应的项目构建目标旁边的框。
  5. 单击应用并确定

  1. Right-click on your project
  2. Choose Properties
  3. Choose Android in the left menu
  4. Tick a box next to the appropriate Project Build Target.
  5. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆