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


当前回答

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

Sudo apt-get安装ia32-libs

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

其他回答

在我的例子中,我试图将我的项目转换为Maven。过了一会儿(和成千上万的随机错误说什么),我试图撤销所有的操作。我没有注意到的是.project文件被更改了,并且在Eclipse中不可见。

只有将.project文件恢复到maven之前的版本才能帮助我修复这个错误。

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未生成甚至消失的问题时,这都是由于XML布局文件中的某些问题导致应用程序无法构建。

我猜你只是复制粘贴了密码,或者没有。无论哪种方法,检查AndroidManifest.xml文件,看看包名是否正确。

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