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


当前回答

确保所有资源文件都没有大写扩展名。我发现我保存了一些带有大写扩展名。png的图像。我把它改成。png,一切都恢复正常了。

其他回答

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

首先查看你的生成文件,看它是否包含你的包名和R.java。 如果它是空的,可能你没有权限创建新文件,所以退出eclipse,然后右键单击,以管理员身份运行,清理项目,一切都会正确。

否则你的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.

重新启动计算机。 除了这种方法,什么也帮不了我

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

那就是:

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

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