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

其他回答

我尝试了上面的大多数方法,但对我的情况不起作用

最后我发现adb输了

对于MAC OS,进入android SDK目录

输入。/adb start-server

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

确保你安装了Android构建工具表单sdk管理器

项目右击属性-> Java BuildPath选择Library并添加android-support.jar。

转到项目->属性->Java构建路径,然后选择订单和导出选项卡。将android-support .jar库设置为选中,并将其置于列表顶部。清理和重建,它适用于大多数情况

安装所有Android SDK构建工具,并删除导入Android。R在你的活动课上。单击项目后->清洁

import android.R;

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.