在Eclipse中,我从源代码创建了一个项目,现在它显示了错误——“R不能被解析为变量”。从我在这里找到的,我已经清除和重建了项目,但R文件仍然没有出现在/gen文件夹中。
什么好主意吗?
在Eclipse中,我从源代码创建了一个项目,现在它显示了错误——“R不能被解析为变量”。从我在这里找到的,我已经清除和重建了项目,但R文件仍然没有出现在/gen文件夹中。
什么好主意吗?
当前回答
我也犯了同样的错误。错误是,我在res/raw文件夹中放置了一个文件,文件名无效。 当我将文件名更正为有效名称时,错误就解决了!
文件命名允许使用的字符:-
1. a-z
2. . _
3. 0-9
4. no capital letters
大写字母是我的问题!
其他回答
有时候你可能会意外地添加一个导入到“R”,所以如果在你的代码顶部你看到一些奇怪的导入,你没有添加自己,删除引用,一切都应该恢复正常
对我来说,建议那些对“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的末尾有一个缺失的斜杠。在Eclipse >首选项> Android > SDK位置
例如,改变
/home/matt/android-sdk-linux
to
/home/matt/android-sdk-linux/
我的问题很奇怪,花了一些时间才找到。src文件的包改变了,包中的最后一个条目被删除了。例如,最初我的类MyActivity.java在包com.abc.client.test.app中,但在我添加了用户权限后,应用程序被删除,包被重命名为com.abc.client.test。我不知道是怎么发生的。重命名包并将java文件放在正确的位置解决了这个问题。
对我来说,项目属性;安卓系统;未设置项目构建目标。我选择了一个Android版本(例如4.2),它修复了它。