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


当前回答

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

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

它会工作得很好。

其他回答

最简单的解决方案——有时您只需要保存正在处理的XML文件,就可以启动自动生成程序。

保存文件(例如main.xml),然后删除R.java文件,看看重新生成的R.java是否解决了R. resolve问题。

有时,手动创建R.java文件会有帮助,只是简单的空R.java。

我的解决方案(在Eclipse Juno上)是点击“Fix Project properties”,通过:

在项目上单击鼠标右键 选择Android工具菜单 单击修复项目属性

ps.首先检查R库是否未实现,res/文件夹中的所有文件是否正常。

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.

这个作品。

步骤1:

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

步骤2:

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

步骤3:

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

享受。快乐的编码。