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

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

享受。快乐的编码。

其他回答

不幸的是,现有的问题没有一个有用。由于我的问题似乎是平台特定的,这可能只适用于如果你是Ubuntu 64位(我目前使用Ubuntu 12)。 一开始我没有看到“问题”窗口,它已经暗示了一个解决方案,在64位环境中,你需要32位库,这可能会丢失:

Sudo apt-get安装ia32-libs

我安装了软件包并重新构建了我的项目,这为我解决了这个问题。

通常情况下,这是因为您在创建项目时提供的MinSDK版本号。例子:

如果你想把2.1作为最小值,Android 2.1实际上是API Level 7。

当你浏览下载并安装的SDK时,你就会明白我在说什么。导航到你安装SDK的地方(C:\android-sdk-windows为例),打开名为“平台”的文件夹。你会看到像“android-7”这样的东西被列为一个文件夹,如果你打开它,就会有一个源代码。属性文件,当用文本编辑器打开时,将显示相应的平台版本。

当你创建一个项目时,你必须选择一个“Build Target”API,该列表中名为“API Level”的最后一列显示了你在填充MinSDK设置时所寻找的数字。

这可能是导致R.java文件没有在Project > gen > packagename > R.java下创建的最常见错误之一。

用包名导入R类。不导入android R类。

So I have run into this problem multiple times when switching build targets. Usually doing a Project >> Clean worked for me. This last time, however, it did not. Finally I tried to open my default.properties file, located under the root project folder. I received an error message stating that it was out of sync with the file system. I actually deleted it and copied a coworkers version which allowed eclipse to rebuild my R file. I will paste what it looks like below. It is named 'default.properties'.

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
# 
# This file must be checked in Version Control Systems.
# 
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-3

我有这个问题很多次,我发现有时“R不会解决”,因为:

一些坏的资源已经存在,例如:一个名为My image .png的图像 或者在资源中出现一些错误,比如在xml文件中出现错误,或者在你的表单中定义资源时出现错误。

在这种情况下,你甚至不能将你自己的包R导入到你的项目中。所以去你的资源文件夹,搜索以上两点。

这是可行的