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


当前回答

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在android项目中是自动生成的资源,有时会发生这种情况,不知道为什么,但你试着从项目中自动生成选项

删除其他项目或android.r文件的其他导入 =>总是记住,如果你总是面临自动生成id或自动删除R文件的问题,你可以生成静态id,如字符串文件,并使用@id而不是@+id

我也有同样的问题。在我的情况下,必须与布局XML文件名。我有一些大写字母的文件名:

xml -没有工作!

xml -正常工作!

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

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

我尝试了上面的大多数方法,但对我的情况不起作用

最后我发现adb输了

对于MAC OS,进入android SDK目录

输入。/adb start-server

这个错误突然出现在我的x64 Linux Mint安装中。结果是ADB二进制文件失败,因为没有安装ia32-libs包。只需运行apt-get install ia32-libs并重新启动Eclipse即可修复该错误。

如果你的x64发行版没有ia32-libs,你将不得不使用Multiarch。

检查这篇文章的#4和#5: http://crunchbang.org/forums/viewtopic.php?pid=277883#p277883

希望这能帮助到一些人。