關於原因網上有好多,比如
1.有時候eclipse不自動編譯,把project clean一下,讓R.java重新生成
2.選擇菜單 Project >> Clean ,前提是勾選上 Bulid Automatically(自動構建部署) , 點Clean后會重新構建項目,因為一般情況下,R.java文件在這個時候會重新更新生成一邊,如果工程有錯,就不會自動生成。
3.選擇工程,右鍵 Android Tools >> Fix Project Properties 這個操作有時候可以修正一些錯誤。
4.舊版本1.5/1.6/2.1 的SDK layout_height里面沒有看到match_parent這個屬性,android:layout_height="match_parent" 這個屬性會導致xml編譯不了不能生成R.java
這個是把高級版本的降級后可能會出現的情況,解決辦法就是把match_parent換成fill_parent
當導入其它源碼時候,首先要保證源碼的SDK版本和你eclipse默認版本是否一致。
5.項目中有其他xml和類錯誤的時候不會自動編譯,jar包引用有錯誤的時候也會導致不會自動編譯。
今天我在導入項目的時候發現styles.xml這個文件有如下代碼
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
發現這個theme會導致xml文件出錯,刪除就可以了,然后R文件生成
