我刚刚下载并安装了新的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 drawables:
[2015-11-26 18:59:48 - MyAndroidApp]
/Users/myname/git/MyAndroidApp/res/menu/drawer_view.xml:24:
error: Error: Resource is not public. (at 'icon' with value
'@android:drawable/ic_menu_home').
有趣的是,直到我使用图标删除了对文件的引用,这个错误才出现在控制台中。
android:entries="@menu/drawer_view"
现在解决方案非常明显,将图标复制到我的项目(res/draw - xxxx /)并切换到本地引用。
@drawable/ic_menu_home
希望这能有所帮助。
I had tried all of the above with no prevail. It turned out PhoneGap was causing a conflict with the Android SDK. After uninstalling PhoneGap, the Resources file started regenerating again. Another project, needed PhoneGap so I re-installed, and once again, the Android project (a different project) stopped auto-generating the R file - Build Automatically was checked, did the Clean, and restarted Eclipse - no dice. I removed PhoneGap and it was working once again. This was PhoneGap v 1.5 with the MDS 1.1 plugin for Eclipse.