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


当前回答

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

其他回答

您可能需要更新SDK工具。重新启动Android SDK管理器,并安装一个新项目:Android SDK Build-tools。

威尔说的对吗

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

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

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

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

您可能需要更新/安装SDK工具。重新启动Android SDK管理器,并安装一个新项目:Android SDK Build-tools。逐个删除,修正哪一个适合你。

如果您使用eclipse:有时eclipse会抑制资源文件中的错误消息。 解决方案:在布局文件夹中保存一个没有错误的临时资源。 重新构建项目。然后eclipse在资源文件中显示正确的错误。 删除临时资源。