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


当前回答

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.

其他回答

哦,上帝,我是Linux (ubuntu),我是这样解决的:

第一件事的问题是权限问题,我没有看到任何权限相关的错误,但这是问题。该工具没有可执行权限。

因此,这只是一个快速修复(如果您知道需要可执行权限的确切文件,则专门对它们应用ff命令)。

更改到你的sdk的目录,然后:

sudo chmod +x -R .

之后去项目->清洁->选择你的项目->清洁

这招对我很管用!

我猜你只是复制粘贴了密码,或者没有。无论哪种方法,检查AndroidManifest.xml文件,看看包名是否正确。

如果您使用的是Mac,请检查. ds_store是否已添加到/res目录中(终端命令行中的ls -al)。删除它并刷新/重建。

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

最后我发现adb输了

对于MAC OS,进入android SDK目录

输入。/adb start-server

按Alt+enter并导入

or

Ctrl + F9

和解决。