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


当前回答

在我的情况下,我的AndroidManifest.xml有一个错误。其他人说你的XML文件必须没有错误,但我只在res/文件夹里看了看。发现并修复尽可能多的错误,问题就会自行解决。

其他回答

哦,上帝,我是Linux (ubuntu),我是这样解决的:

第一件事的问题是权限问题,我没有看到任何权限相关的错误,但这是问题。该工具没有可执行权限。

因此,这只是一个快速修复(如果您知道需要可执行权限的确切文件,则专门对它们应用ff命令)。

更改到你的sdk的目录,然后:

sudo chmod +x -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.java可能无法自动生成的另一个原因是,如果您有res/ drawablehdpi、res/ drawablemdpi或res/ drawableldpi这样的目录。

1.6+似乎对这些目录没有问题,但1.5不需要它们。当我删除这些目录时,R.java再次开始为我自动生成。

R是一个生成的类。如果你正在使用Android开发工具(ADT),它会在项目构建时生成。您可能已经关闭了“自动构建”。