简体   繁体   English

删除完全未使用的XML文件,清理后R.java无法自动生成

[英]Deleting completely unused XML file, R.java not auto-generating after clean

I just deleted an XML file from my project that had not been used in several weeks and was not referenced once in any of the files that I myself had coded. 我只是从项目中删除了一个XML文件,该文件已经好几个星期没有使用过,并且在我自己编写的任何文件中都没有被引用过。 After deleting it, I have 79 errors claiming that everything pointing to the R.java file "cannot be resolved or is not a field". 删除后,我有79个错误,声称指向R.java文件的所有内容“无法解析或不是字段”。 I have restarted Eclipse, my computer, cleaned and rebuilt several times. 我已经重新启动了Eclipse和计算机,并对其进行了多次清理和重建。 I cannot seem to find anyway of adding the file back. 无论如何,我似乎都找不到将文件添加回去的方法。 How can I fix this? 我怎样才能解决这个问题?

Edit: R.java does not exist at all currently in my project. 编辑:我的项目中目前根本不存在R.java。

Edit 2: Here is my console output: C:\\Users\\Matt\\workspace\\BarJinx\\res\\menu\\login_picker.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/action_forgot_password'). 编辑2:这是我的控制台输出:C:\\ Users \\ Matt \\ workspace \\ BarJinx \\ res \\ menu \\ login_picker.xml:3:错误:错误:找不到与给定名称匹配的资源(“ title”中的值为' @ string / action_forgot_password')。

Here is my login_picker.xml code: 这是我的login_picker.xml代码:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/action_forgot_password"
    android:showAsAction="never"
    android:title="@string/action_forgot_password"/>

</menu>

A couple of things you can try.- 您可以尝试一些方法。-

  • I'm guessing you're not connected to a svn repository, but still you can try right-click on Project => Restore From local history... , just to make sure the file you deleted is causing the problem (if you closed eclipse this may not work, though) 我猜您没有连接到svn信息库,但仍然可以尝试右键单击Project => Restore From local history... ,以确保删除的文件引起了问题(如果关闭了蚀这可能不起作用,但是)

  • Double check Problems tab ; 仔细检查Problems tab ; it may give you a clue about why R is not being generated (usually related with some issue keeping the project source to compile) 它可能会为您提供一个有关为什么未生成R的线索(通常与保持项目源代码编译的某些问题有关)

  • Go to Android properties , change the Android Target Version and accept. 转到Android properties ,更改Android Target Version并接受。

  • Click on Android Tools => Fix Project Properties 单击Android Tools => Fix Project Properties

  • Check Project => Java build path for build path issues. 检查Project => Java build path以了解构建路径问题。

Hope it helps. 希望能帮助到你。

Your resource file will not automatically re-create itself if you have red squiglies, syntax errors that prevent your code from compiling. 如果您有红色波浪形(语法错误,导致代码无法编译),则资源文件不会自动重新创建自己。 By this critical file Resources not re-created you get lots of errors. 通过此关键文件,无法重新创建的资源会导致很多错误。 That is to be expected. 这是可以预料的。 To fix your problem open the file C:\\Users\\Matt\\workspace\\BarJinx\\res\\values\\strings.xml and add this line 要解决您的问题,请打开文件C:\\ Users \\ Matt \\ workspace \\ BarJinx \\ res \\ values \\ strings.xml并添加以下行

You can add/edit strings from your ide if that helps if you are using eclipse click on the resources tab, good luck. 如果您使用的是eclipse,那么可以从IDE中添加/编辑字符串,如果好用,请单击“资源”选项卡。

I am sorry that was the main part you needed 抱歉,这是您需要的主要部分

<string name="action_forgot_password">So you forgot your password</string>

or alternatively you can just add a string in your login_picker.xml file 或者,您也可以在login_picker.xml文件中添加一个字符串

"so you forgot your password"

Let me just explain the first way is best because you can't assume the user will speak English. 让我解释一下第一种方法是最好的,因为您不能假设用户会说英语。 Later on you will see why strings are stored separate in a strings file or many string files one for each language. 稍后,您将了解为什么将字符串分别存储在一个字符串文件中,或将每种语言分别存储在多个字符串文件中的原因。 If the app is run on a device set to Spanish for example you would first need a file strings.es witch has this line 例如,如果应用程序在设置为西班牙语的设备上运行,则首先需要文件字符串。

<string name="action_forgot_password">El So you forgot your password</string>

Sorry I don't speak Spanish but I hope you get why they use this round about way of referencing strings from another file in an indirect way. 抱歉,我不会说西班牙语,但是我希望您能理解为什么他们使用这种方式以间接方式引用另一个文件中的字符串。 It is the android way. 这是android方式。 You also can't assume the device that runs you app will have a small display so you will eventually make many layouts, one for each screen size and that is why you have many drawable files one for each. 您也不能假设运行您的应用程序的设备的显示屏会很小,因此您最终会布局很多,每个屏幕尺寸一个,这就是为什么您有很多可绘制文件的原因。

So after doing the "Delete all android.R imports from each file" thing several times, going to sleep, and doing it again the next morning, it actually worked. 因此,多次执行“删除每个文件中的所有android.R导入”操作后,进入睡眠状态,并在第二天早上再次进行此操作,它实际上就可以了。 Sometimes I hate eclipse. 有时我讨厌日食。

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

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