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


当前回答

我用窗口->首选项->Android和SDK解决了这个问题,位置:adt\ SDK的路径,例如C:\adt\ SDK

其他回答

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

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

它会工作得很好。

首先检查是否有任何错误在任何xml布局,如果然后解决它首先。

否则,从项目中删除junit依赖项并重新构建项目。

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.

R有两种出错的方式

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

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

这将解决问题。

检查XML文件名。确保它们都是小写的。

还要确保所有图像资源名称也都是小写的。我在我的jpg文件的名称中有一个大写字母,这在我的项目中导致了R未解决的错误。