在Eclipse中,我从源代码创建了一个项目,现在它显示了错误——“R不能被解析为变量”。从我在这里找到的,我已经清除和重建了项目,但R文件仍然没有出现在/gen文件夹中。

什么好主意吗?


当前回答

对我来说,建议那些对“R”文件有问题的人的最佳解决方案是尝试以下步骤(顺序不重要):

update ADT & SDK , Eclipse and Java. remove gen folder , and create it again . do a clean-project. right click the project and choose android-tools -> fix-project-properties . right click the project and choose properties -> java-build-path -> order-and-export. make sure the order is : Android 4.3 (always the latest version) Android private libraries android dependencies your library project/s if needed yourAppProject/gen yourAppProject/src make sure all files in the res folder's subfolders have names that are ok : only lowercase letters, digits and underscore ("_") . always make sure the targetSdk is pointed to the latest API (currently 18) , and set it in the project.properties file

其他回答

尝试修改AndroidManifest文件。

例如,添加空格并删除此空格。操作完成后,保存项目。刷新资源。这是有帮助的。

我有类似的问题和解决方案,我发现在任何资源 文件即背景,声音等必须不包含大写字母或 除_之外的任何特殊符号

我也犯了同样的错误。错误是,我在res/raw文件夹中放置了一个文件,文件名无效。 当我将文件名更正为有效名称时,错误就解决了!

文件命名允许使用的字符:-

1. a-z
2. . _
3. 0-9
4. no capital letters

大写字母是我的问题!

问题是eclipse没有生成R.java。 要解决这个问题,请转到项目->clean…选择你的项目,选择ok,然后清理和构建项目,导入你的包名R文件(Ex com.demo.R)。它的工作原理。

我遇到了这个问题,其他指南都没有帮助,然后我意识到我的系统上没有安装java jdk。如果您还没有这样做,请下载与您安装的eclipse版本对应的版本(x86或x64)。