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


当前回答

值得在AndroidManifest.xml中检查一下。属性包的值正确。

那就是:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="your.correct.package.name"
   ...

更改后,将重新生成R.java。

其他回答

每次我遇到R未生成甚至消失的问题时,这都是由于XML布局文件中的某些问题导致应用程序无法构建。

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

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

有时,手动创建R.java文件会有帮助,只是简单的空R.java。

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.

我也面临着同样的问题,我在谷歌上搜索并尝试了我找到的建议,但没有一个对我有用。我改变了我的工作空间,它起作用了,但在改变你的工作空间之前,试试其他的工作方法。任何一个都可能对你有用。