我刚刚下载并安装了新的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未生成甚至消失的问题时,这都是由于XML布局文件中的某些问题导致应用程序无法构建。

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

其他回答

您可能需要更新SDK工具。重新启动Android SDK管理器,并安装一个新项目:Android SDK Build-tools。

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

发生这种情况的另一种方式是,从其中一个示例启动一个新项目。当您稍后决定将包名从com.example.android.foo更改为您自己的域时,您将需要修改清单和单个.java文件中的几个值。

如果您使用的是Eclipse,请找到.java文件的包语句并选择QuickFix。这里可能有几个选项,但你想要的是指示“移动‘foo.java’到打包‘com.youdomain.android.yourapp’”的选项。保存文件,它可以自动构建或做其他人建议,并尝试“项目->清洁”。

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.drawable。*该文件存在于可绘制的*文件夹中。