我刚刚下载并安装了新的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.java不能自动生成的原因是如果你有这样的目录

res/drawable-hdpi, 
res/drawable-mdpi, 
res/drawable-ldpi.

image name should be in a proper way

检查映像名称 并检查和布局/any.xml 和string.xml

其他回答

还有一件事可能会导致这个问题:

我安装了新的ADT(第22节)。它停止创建包含R.java的gen文件夹。解决方案是在Android SDK管理器中安装新的Android SDK构建工具。

在这里找到解决方案

最近,我遇到了类似的R无法解决的情况。

项目->清洁(它通常工作,但这次没有)。 我试图删除生成/文件夹(自动生成)-没有。 虚拟修改文件。不了。现在我头发已经变白了! 我在AndroidManifest.xml文件中检查appName是否存在。它被检查过了! 再次查看我的res/文件夹…

这就是奇怪的地方…它给出了一个错误,在某些情况下,但不是所有情况下。

我添加了格式化="false"标志:

<resources>
    <string name="blablah" formatted="false">
    </string>
</resources>

宾果!

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.

从这里提供的许多答案来看,帮助我的是在java构建路径的“order and Export”中更改顺序。

1.单击您的项目->项目属性

2.Java构建路径

3.订购及出口

将Build类路径的顺序更改为

1 .(软件包名称)/ src

2.Android(版本号)

3.Android依赖关系

4 .(软件包名称)/ gen

只是清理和重建你的项目有时会有帮助