在Eclipse中,我从源代码创建了一个项目,现在它显示了错误——“R不能被解析为变量”。从我在这里找到的,我已经清除和重建了项目,但R文件仍然没有出现在/gen文件夹中。
什么好主意吗?
在Eclipse中,我从源代码创建了一个项目,现在它显示了错误——“R不能被解析为变量”。从我在这里找到的,我已经清除和重建了项目,但R文件仍然没有出现在/gen文件夹中。
什么好主意吗?
当前回答
检查androidmanifest.xml文件和layoutfolder xml文件。它们应该被正确地创建,因为xml中的开始和结束子句应该被正确地放置。更新文件,清理和构建。都准备好了!
其他回答
有时候你可能会意外地添加一个导入到“R”,所以如果在你的代码顶部你看到一些奇怪的导入,你没有添加自己,删除引用,一切都应该恢复正常
不要担心。首先,您可以清理项目,然后运行项目。如果这不起作用,请点击以下链接:
这里是解决这个问题的最佳方法:[Android开发-我的R.Java文件在哪里?]] [2] R.java不能再生 R无法解决- Android错误 R不能被解析为一个变量 R不能解析为一个变量—邮件列表条目 修正:R不能被解析为一个变量
我一直有这个,我确实跟踪它回到布局文件..它再次发生在我身上,但我不能在布局文件中找到任何东西。我在string.xml中找到了它。其中一个字符串名称以cap开头,这导致了问题。
对我来说,建议那些对“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
我的设置在最近的更新后被打破,其中SDK构建工具需要在SDK安装后单独安装。所以构建工具更新+ Eclipse重新启动为我修复了这个问题。
信用归于这里的Android回复