2

I made a mistake an edited a button id instead of the text. It contained special characters and now it's broken. I changed the id and now the new one appears in the R.java file too, but the old one didn't get removed. I tried deleting that one from the file using a texteditor, but after starting Eclipse it was regenerated and it was there again.

How do I remove that entry from R.java? I've tried cleaning the project.

MikkoP
  • 4,864
  • 16
  • 58
  • 106
  • 1
    Delete your R.java and clean rebuild your project. – Jitender Dev Dec 29 '13 at 14:43
  • Try the answer mentioned in this [question](http://stackoverflow.com/questions/20782771/r-java-missing-r-cannot-be-resolved-to-a-variable-even-if-no-mistake-in-xml-fi) – Vivek Warde Dec 29 '13 at 14:47
  • @Brontok already tried that. – MikkoP Dec 29 '13 at 15:08
  • @VivekWarde I've tried those too, no luck. – MikkoP Dec 29 '13 at 15:09
  • Try this: Untick `Build Automatically` in `Project`, delete your `R` file, change the id in the layout, then retick `Build Automatically`. – hichris123 Dec 31 '13 at 22:30
  • @hichris123 Thanks for your comment. Unfortunately this didn't work. Seems like the faulty entry has the id value of `0x7f08000a` and the right one `0x7f080008`. – MikkoP Jan 01 '14 at 12:39
  • @MikkoP I deleted my question, let's wait a few hours and maybe your lost reputation points will come back so you can start a bounty again. In the worst case I can set a bounty on your question myself to give you back your lost points. – janos Jan 06 '14 at 11:54
  • @janos Thanks for trying though. There's no need to try to award me those points back. It was just a few points =) – MikkoP Jan 06 '14 at 11:55

4 Answers4

1

I created a new project and manually created the files again. I copy pasted the text from the old files and now it is working again.

MikkoP
  • 4,864
  • 16
  • 58
  • 106
0

Delete the R.java file. It will be regenerated again on your next build with a non-cached version.

Clean project works fine. In Eclipse if you just change some xml components, it doesn't always generate a new R file. Cleaning your project does it.

Rahul Gupta
  • 5,275
  • 8
  • 35
  • 66
  • If I delete R.java it will be regenerated immediately. It has still that faulty entry after that. Also, if I edit an XML file and clean it, it has no effect in that entry either. – MikkoP Dec 29 '13 at 17:14
  • so let that entry remain. This sometime's happen. What i do is that in the graphical layout for the xml file, for that particular widget, i change the id from its properties, then refractoring happens and it is replaced from its every occurrences including R.Java – Rahul Gupta Dec 29 '13 at 17:24
  • Changing the name from the graphical editor doesn't work. It says `A fatal error occurred while performing the refactorin. This refactoring cannot be performed correctly due to syntax errors in the compilation unit. To perform this operation you will need to fix the errors.` – MikkoP Dec 29 '13 at 17:41
  • syntax errors ok. Check your syntax. check your Error log. something is wrong there and it is in your xml only not in you class file. It can be either in xml or drawables name, basically in the res folder – Rahul Gupta Dec 29 '13 at 17:48
  • The only error for this project is `Syntax error on token "Invalid Character", , expected` which is from R.java on line 304 and it is the faulty line `public static final int Pysäköintikielto=0x7f08000a;`. – MikkoP Dec 29 '13 at 18:04
  • What symbols are you using ? Java has defined only certain special characters you can use when declare something. Obviously you are using certain special characters. Please use only alphabets to avoid such errors – Rahul Gupta Dec 29 '13 at 18:20
  • As I said in the question, I made a mistake and edited the id instead of the text of the button. It should say "Pysäköintikielto". – MikkoP Dec 29 '13 at 18:33
0

You said you tried deleting it, and it regenerated the error? Try deleting it once more in Eclipse, then save the file. Afterwards, try cleaning the project. Hope I helped. :)

frgnvola
  • 518
  • 3
  • 16
0

Try the most paranoid possible cleaning:

  1. Switch off Project | Build Automatically
  2. Delete the entire bin folder, and the content of the gen folder (gen/*, keeping gen itself).
  3. Build manually with Project | Build.
  4. If looks good then switch back on Project | Build Automatically

If even this doesn't work, then:

  1. Backup your project
  2. Create a new project directory, ideally by a fresh checkout from your VCS. If you don't use a VCS then copy all files from the old project except generated files, and Eclipse's files like .project, .classpath, .settings, and so on.
  3. Import the new project into Eclipse with File | Import... | Existing Projects into Workspace (or if you use Maven then ... | Existing Maven Projects)
janos
  • 120,954
  • 29
  • 226
  • 236
  • Edit... ash, managed to award you the bounty already. Running the project created the problem again. – MikkoP Jan 06 '14 at 10:19
  • @MikkoP oh crap. You cannot un-award it? I'll stick with you and try to get to the bottom of your android issue, but in the meantime we should try to get to cancel the award. – janos Jan 06 '14 at 10:39
  • Hmm... I tried creating a new project and copying the files to that one. I copied only the Java files and the resource files and it generated the same error. – MikkoP Jan 06 '14 at 11:45
  • @MikkoP is the project open source so I can reproduce at my end? – janos Jan 06 '14 at 11:46