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


当前回答

真正的问题是如何防止android.R;返回:

窗口-> Prefs -> Java ->编辑器->保存动作

取消勾选“组织导入”。

这样就行了。

其他回答

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

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

最后我发现adb输了

对于MAC OS,进入android SDK目录

输入。/adb start-server

我也面临着同样的问题,我在谷歌上搜索并尝试了我找到的建议,但没有一个对我有用。我改变了我的工作空间,它起作用了,但在改变你的工作空间之前,试试其他的工作方法。任何一个都可能对你有用。

我的问题是,我从strings.xml中的字符串中遗漏了=标记 例如:<string name"dialog_grl…" 即使在我的.xml文件的图形布局无法显示字符串时,我也没有发现它。在一次项目清理后,所有文件都被弄乱了。

解决方案:

Eclipse重新启动后项目干净。它们是自动生成的,否则你是XML内部的任何组件(如按钮)后按Ctrl + Shift + o。它自动生成R文件,然后错误就解决了。