android r.java will not update
I googled a lot to find various hints what could cause this problem. Many of them on this forum, but nothing works.
I installed the sdk from scratch on 3 different machines (xp, macos snow leopard, leopard) and always the same problem, that even the sample code in the android sdk doesn't compile. Af开发者_StackOverflow中文版ter hours of looking through the xml files I recognized, that when I remove ' from strings the sample code of the sdk will compile. So does a new project, as long there is no change needed in the R.java file. As soon as I try to add a button with findViewByID, I get the error that the field R.id cannot be resolved. No other changes were done to the project.
As mentioned before I tried various things, including: clean project, rebuild restart eclipse update sdk (even tough I installed the new sdk) no uppercase letters ... Install sdk, latest eclipse classic on a clean machine
I don't think it's an issue of the code itself, because even the sample code provided by the sdk doesn't compile without removing ' from the xml.
Please somebody has some hints and ideas where to look next please?
open the "problems" window in eclipse, if there are any issues in any of the xml files, R.java will not generate.
if there are single quotes in the xml files, they should be replaced with double quotes. the XML standard is that all attribute values be surrounded by double quotes, not single quotes.
Invalid
<?xml version='1.0' encoding='utf-8' ?>
<resources>
<string name='some_name'>value</string>
</resources>
Valid
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<string name="some_name">value</string>
</resources>
The easiest way to see what went wrong in Eclipse is to go to Window>Show View>Other>General>Error Log
If you are using Eclipse, under Package Explorer, in your project, find res\layout\activity_(activity name).xml and right click and open it with text editor. Add under TextView:
android:id = "@+id/button_id"
and clean rebuild your project. Use findViewById(R.id.button_id)
.
With eclipse, make sure Menu->Project->Build automatic is selected.
Then delete all the files in gen/. They should be automatically regenerated. This will force an update to R.java.
精彩评论