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


当前回答

我的R文件消失了,不会生成-控制台报告了这个:

[2010-09-22 16:19:40 - myproject] res\ draw- ldpi\downloadNow.png:无效的文件名:必须只包含[a-z0-9_.]

因此,资源名称不能有大写字母-确认它们都是小写字母并包含。而且只有_

其他回答

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

检查XML文件的内容。如果layout_width或layout_height包含match_parent元素,则将其更改为fill_parent。这为我解决了问题。

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

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

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

此外,如果你的res文件夹中有额外的文件,如“desktop.ini”,这些文件是操作系统添加的,但完全没有必要,试着删除它们。这显然是我导入项目中阻碍生成R.java的原因之一。