I have downloaded code from google codes but when I import that project in my eclipse IDE it does not generate R.Java file.I searched many blogs and forums and tried many th
I still had this error after checking that all my resources had no errors, cleaning, rebuilding, restarting, etc.
I fixed this by filtering out the SVN files from the project.
How to exclude .svn directories from search in Eclipse?
While the question mentions search, the solution pertains to what files are used in compiling as well.
Restarted, and everything was fine.
".xml files" and "image files" and make sure that the names of the lowercase.
I encountered the same problem trying to build the wiktionary sample code I downloaded from code.google.com (here) I had imported into a new Eclipse Juno project set to use Android 4.1 and JDK 1.6.
Here is an excerpt of the console after building the project:
W/ResourceType( 6292): Bad XML block: header size 103 or total size 0 is larger than data size 0 C:\Development\WorkJava\android\sampleapps\Wiktionary\com.example.android.wiktionary.LookupActivity\res\values\strings.xml:23: error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute? C:\Development\WorkJava\android\sampleapps\Wiktionary\com.example.android.wiktionary.LookupActivity\res\values\strings.xml:23: error: Unexpected end tag string
Here's an excerpt of the res/values/string.xml:
<resources>
<string name="app_name">Wiktionary Word of the Day</string>
<string name="app_descrip">A fast Wiktionary browser and Word-of-day widget</string>
<string name="app_credits">"All dictionary content provided by Wiktionary under a GFDL license. http://en.wiktionary.org\n\nIcon derived from Tango Desktop Project under a public domain license. http://tango.freedesktop.org".</string>
<string name="template_user_agent">"%s/%s (Linux; Android)"</string>
<string name="template_wotd_title">"Wiktionary:Word of the day/%s %s"</string>
<string name="template_wotd_archive_title">"Wiktionary:Word_of_the_day/Archive/%s/%s"</string>
SOLUTION
Adding formatted="false" to the 3 last string definitions (containing two %s substitution placeholders), as shown below, solved the problem. Rebuilding the project generated R.java in the gen folder.
<resources>
<string name="app_name">Wiktionary Word of the Day</string>
<string name="app_descrip">A fast Wiktionary browser and Word-of-day widget</string>
<string name="app_credits">"All dictionary content provided by Wiktionary under a GFDL license. http://en.wiktionary.org\n\nIcon derived from Tango Desktop Project under a public domain license. http://tango.freedesktop.org".</string>
<string name="template_user_agent" formatted="false">"%s/%s (Linux; Android)"</string>
<string name="template_wotd_title" formatted="false">"Wiktionary:Word of the day/%s %s"</string>
<string name="template_wotd_archive_title" formatted="false">"Wiktionary:Word_of_the_day/Archive/%s/%s"</string>
In general, to make it work:
But It doesn't, Why?
Because there are some compile error (or bug?) regarding to the xml file in res, so R is not genetared (I've tested on my Mac):
In res/values/styles.xml: commented out the following:
<style name="iWindowTitleBackground" parent="android:WindowTitleBackground">
<item name="android:background">@drawable/title_bar</item>
</style>
In res/values/themes.xml: comment out the following:
<item name="android:windowTitleBackgroundStyle">@style/iWindowTitleBackground</item>
Then do a Project -> Clean, you should get R.java generated.
There is bug reported that parent="android:WindowTitleBackground" cannot be resolved in some operating system, check out here for more details.
Whenever your generated R class isn't generated, it indicates that there's a problem with generating it due to some parsing issue from the XML resources. Check the error console in your IDE to figure out what's specifically wrong.
Common problems are:
strings.xml
, for instance you're
instead of you\'re
layout_width
or layout_height
tags in layout resourcesChange the workspace to new directory and set its permissions such that it is available for everyone