我刚刚下载并安装了新的Android SDK。我想创建一个简单的应用程序来测试它。

向导创建了以下代码:

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不能被分解

在网上

setContentView(R.layout.main);

Why?

PS:我在res/layout/下有一个名为main.xml的XML文件。


当前回答

I had tried all of the above with no prevail. It turned out PhoneGap was causing a conflict with the Android SDK. After uninstalling PhoneGap, the Resources file started regenerating again. Another project, needed PhoneGap so I re-installed, and once again, the Android project (a different project) stopped auto-generating the R file - Build Automatically was checked, did the Clean, and restarted Eclipse - no dice. I removed PhoneGap and it was working once again. This was PhoneGap v 1.5 with the MDS 1.1 plugin for Eclipse.

其他回答

R是一个自动生成的类,它包含用于标识资源的常量。如果你没有R.java文件(在Eclipse的1.5 SDK中是gen/eu.mauriziopz.gps/R.java),我建议关闭并重新打开你的项目,或者转到project > Build all(并选择“自动构建”,而Josef则推荐)。如果这不起作用,那就尝试做一个新的项目,如果问题被重新创建,那就在这里再次发布,我们将更详细地讨论。

它为我工作与右击>Android工具>修复项目属性和重新启动Eclipse后的一些时间。

我按照建议安装了平台构建工具。然后 的消息

<package>/gen already exists but is not a source folder. Convert to a source folder or rename it.

出现在控制台。所以我听从了建议,将“gen”设置为源文件夹。这解决了问题。

R是一个生成的类。如果你正在使用Android开发工具(ADT),它会在项目构建时生成。您可能已经关闭了“自动构建”。

在我的情况下,这个错误是因为我导入了一个图像到文件夹/res,图像有一个无效的名称。真不敢相信,我花了将近一个小时来解决这个问题,直到我意识到图像有一个无效的名称:/