简体   繁体   中英

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. After deleting it, I have 79 errors claiming that everything pointing to the R.java file "cannot be resolved or is not a field". I have restarted Eclipse, my computer, cleaned and rebuilt several times. 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.

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').

Here is my login_picker.xml code:

<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)

  • Double check 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)

  • Go to Android properties , change the Android Target Version and accept.

  • Click on Android Tools => Fix Project Properties

  • Check Project => Java build path for build path issues.

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

You can add/edit strings from your ide if that helps if you are using eclipse click on the resources tab, good luck.

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

"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. 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. Sometimes I hate eclipse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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