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

其他回答

我有Android 8的例子,并试图使用Android 7 SDK。当我关闭项目并重新打开应用程序文件夹并选择使用Android 8 SDK时,它能够找到R文件。希望这能有所帮助。

在运行x64 Linux时,您可能会丢失一些x32构建库。对于Debian,请确保安装了libc6-i386和zlib1g包。

首先检查是否有任何错误在任何xml布局,如果然后解决它首先。

否则,从项目中删除junit依赖项并重新构建项目。

尝试使您的新XML布局文件名小写。例如,使用my_file.xml而不是myFile.xml。

我尝试了上面的大多数方法,但对我的情况不起作用

最后我发现adb输了

对于MAC OS,进入android SDK目录

输入。/adb start-server