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


当前回答

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

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

其他回答

这可能是由于手动重命名AndroidManifest.xml中的包而导致的问题

另一种选择是使用内置工具重命名包,这将照顾到大多数问题,避免R not found问题。

Right Click on the project
Click on Android Tools
Click on Rename Application Project
Enter the new package name

然后将出现一个弹出窗口,要求应用更改,包括R工作区。

在android中重命名包名

关闭所有文件,清理项目,重新启动Eclipse。

or

R是一个自动生成的类,它包含用于标识资源的常量。如果你没有R.java文件(在Eclipse的1.5 SDK中是gen/eu.mauriziopz.gps/R.java),我建议关闭并重新打开你的项目,或者转到project > Build all(并选择“自动构建”,而Josef则推荐)。如果这行不通,那就试着做一个新项目

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:

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

享受。快乐的编码。

将构建目标从1.5或1.6更改为2.2 (API版本8),并检查string.xml中是否有%字符。如果是,则替换为%%。