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


当前回答

这个作品。

步骤1:

下载https://www.dropbox.com/s/7nwlrg05ke05tat/GalleryImageview.zip

步骤2:

加载eclipse和加载项目>运行和测试将在运行中工作

步骤3:

如果有任何错误,请在这里更新。

享受。快乐的编码。

其他回答

威尔说的对吗

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

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

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

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.

我有Android 8的例子,并试图使用Android 7 SDK。当我关闭项目并重新打开应用程序文件夹并选择使用Android 8 SDK时,它能够找到R文件。希望这能有所帮助。

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

I had tried all of the above with no prevail. It turned out PhoneGap was causing a conflict with the Android SDK. After uninstalling PhoneGap, the Resources file started regenerating again. Another project, needed PhoneGap so I re-installed, and once again, the Android project (a different project) stopped auto-generating the R file - Build Automatically was checked, did the Clean, and restarted Eclipse - no dice. I removed PhoneGap and it was working once again. This was PhoneGap v 1.5 with the MDS 1.1 plugin for Eclipse.