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


当前回答

对我来说,这是因为错误的java编译器版本。 项目属性-> Java编译器,启用“启用项目特定设置”,并选择您的“编译器遵从级别”

其他回答

So I have run into this problem multiple times when switching build targets. Usually doing a Project >> Clean worked for me. This last time, however, it did not. Finally I tried to open my default.properties file, located under the root project folder. I received an error message stating that it was out of sync with the file system. I actually deleted it and copied a coworkers version which allowed eclipse to rebuild my R file. I will paste what it looks like below. It is named 'default.properties'.

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
# 
# This file must be checked in Version Control Systems.
# 
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-3

用包名导入R类。不导入android R类。

只需进入Android Top菜单列表。点击构建菜单,在构建下点击重建项目。

威尔说的对吗

R是一个自动生成的类,它包含用于标识>资源的常量。如果你没有R.java文件(它将是gen/eu.mauriziopz.gps/R.java在>Eclipse与1.5 SDK),我建议关闭和重新打开你的项目或去>项目>构建所有(并选择“自动构建”,而>Josef的建议)。如果这不起作用,那就尝试做一个新项目,如果问题是重新创建的,那么>帖子在这里再次发布,我们将更详细地介绍。

但我发现还有另一个问题导致了第一个问题。SDK目录中的工具没有被执行的权限,所以它就像Eclipse不存在一样,因此它没有构建R.java文件。

因此,修改权限并选择“自动构建”就解决了这个问题。

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

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

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

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

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

宾果!