简体   繁体   English

清理项目没有修复R.java错误(Android)

[英]Cleaning Project not fixing R.java errors (Android)

My Android project just started saying all my R.blah.blah references are errors. 我的Android项目刚开始说我所有的R.blah.blah引用都是错误的。 Cleaning/re-generating the R.java file has not fixed it. 清理/重新生成R.java文件还没有修复它。 Nor has closing/reopening the project/eclipse. 也没有关闭/重新开放项目/日食。 I undid any changes to xml files that could have caused it. 我解除了可能导致它的xml文件的任何更改。 This is only occurring in ONE of my activities, all other activities do not have any errors related to R.blah. 这只发生在我的一项活动中,所有其他活动都没有与R.blah有关的任何错误。

Note: R.java does have all the correct references in the file. 注意:R.java确实在文件中包含所有正确的引用。

check if 检查是否

import android.R;

is in your classes and remove it then try 在您的课程中删除它然后尝试

If you copy code from other project you get some,lines like 如果您从其他项目中复制代码,则可以获得一些代码

import android.R.com.example.view.Widget
import android.R.com.hardware.Camera 

Remove those lines and run it. 删除这些行并运行它。

To avoid the hussle ,another simple solution is to restart eclipse. 为了避免麻烦,另一个简单的解决方案是重启eclipse。 This time change the directory of your workspace. 这次更改工作区的目录。 And import your project from the previous workspace into the new one . 并将项目从以前的工作区导入到新工作区中。 Viola.it works. Viola.it有效。 So far as you have not violated naming conventions in your xml files (Remember all ids in xml must be small letters) . 只要您没有违反xml文件中的命名约定(请记住xml中的所有ID必须是小写字母)。 This should work. 这应该工作。

这可能是您的xml数据错误。请检查您的xml文件, 请参阅此处 ,然后清理您的项目并构建它。检查R.java文件是否自动生成。

只是在发生错误的特定活动中尝试一下

    import your_package_name.R;

The line android:text="@string/Get Location" causes as error in R.java because string Get Location have a gap in it. android:text="@string/Get Location"导致R.java中的错误,因为字符串Get Location在其中有一个间隙。

To correct it use an underscore between two names: Get_Location 要更正它,请使用两个名称之间的下划线: Get_Location

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM