简体   繁体   中英

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. After 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>

要查看Eclipse中出了什么问题,最简单的方法是转到“窗口”>“显示视图”>“其他”>“常规”>“错误日志”

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.

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