我刚刚下载并安装了新的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有两种出错的方式

1)布局文件ie xml文件的问题

2)如果你更新adt,那么就会出现R问题。 -你必须检查项目的属性 - goto->属性->Java构建路径->命令和导出,并检查所有的lib。

这将解决问题。

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

对我来说,这是因为使用了“私人”android drawables:

[2015-11-26 18:59:48 - MyAndroidApp] 
/Users/myname/git/MyAndroidApp/res/menu/drawer_view.xml:24: 
error: Error: Resource is not public. (at 'icon' with value 
'@android:drawable/ic_menu_home').

有趣的是,直到我使用图标删除了对文件的引用,这个错误才出现在控制台中。

android:entries="@menu/drawer_view"

现在解决方案非常明显,将图标复制到我的项目(res/draw - xxxx /)并切换到本地引用。

@drawable/ic_menu_home

希望这能有所帮助。

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

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.