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


当前回答

在运行x64 Linux时,您可能会丢失一些x32构建库。对于Debian,请确保安装了libc6-i386和zlib1g包。

其他回答

我认为问题出在layout.xml文件或import语句中。

请确保您没有导入R.android。,而不是导入R.YOUR PACKAGE NAME..

它会工作得很好。

I would say "R can not be resolved" is something too general and can be misleading at times. I also had the same problem many times ago even when I first create a new project (which mean I did not mess with the code yet). Most of the time I just need to update my sdk manager (as some people have mentioned). But in my recent case, I found out that the path to my project file is too long (something like this E:\R&D\ANDROID\ANDROID BASIC\Folder 1\ Folder 2\..... \Folder n\MyProject). The folder names also contain spaces character. I thought it could be the case and indeed it's true, when I created a new project in another folder with shortest path possible, and none of the folders' names containing space character, it worked as normal.

我也有这个问题。结果发现我无意中从strings.xml文件中删除了“app_name”字符串资源,这导致了一个无声错误。一旦我重新添加了它,R类就成功生成了,一切都恢复并运行了。

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

R是一个自动生成的类,它包含用于标识资源的常量。如果你没有R.java文件(在Eclipse的1.5 SDK中是gen/eu.mauriziopz.gps/R.java),我建议关闭并重新打开你的项目,或者转到project > Build all(并选择“自动构建”,而Josef则推荐)。如果这不起作用,那就尝试做一个新的项目,如果问题被重新创建,那就在这里再次发布,我们将更详细地讨论。