Domanda

Ho scaricato il codice da google codici ma quando ho importare quel progetto in il mio IDE Eclipse non genera R.Java file.I cercato molti blog e forum e provato molte cose come la pulizia, la ricostruzione, la creazione di progetti da fonte ecc esistente, ma ancora di fronte al popolo problema.Alcuni detto che a volte è causato dal software client SVN, ma nessuno di loro menzionato alcuna soluzione per that.I sarà molto grato a voi ragazzi, se si scarica da soli e trovare ciò che è l'esatto problema.

È stato utile?

Soluzione

In generale, per farlo funzionare:

  1. progetto importazione in Eclipse (File -> Import -> Generale -> progetti esistenti nello spazio di lavoro)
  2. in Eclipse, creare manualmente la cartella gen e aggiungerlo come cartella di origine (tasto destro del mouse sul progetto, costruire il percorso -> Configura costruire il percorso -> Aggiungi cartella)
  3. Pulire il progetto, si suppone per ottenere R.java generata

Ma non, perché?

Perché ci sono alcuni errori di compilazione (? O bug) per quanto riguarda il file xml nella res, quindi R non è genetared (ho testato sul mio Mac):
In res / Valori / styles.xml: commentata il seguente:

<style name="iWindowTitleBackground" parent="android:WindowTitleBackground">    
  <item name="android:background">@drawable/title_bar</item>        
</style>

In res / Valori / themes.xml: commento il seguente:

<item name="android:windowTitleBackgroundStyle">@style/iWindowTitleBackground</item>

Poi fare un progetto -> Clean, si dovrebbe ottenere R.java generato.

C'è bug ha riferito che parent = "android: WindowTitleBackground" non può essere risolto in un sistema operativo, controlla qui per maggiori dettagli.

Altri suggerimenti

Ogni volta che la classe R generata non viene generato, significa che c'è un problema con la generazione di esso a causa di qualche problema di analisi dalle risorse XML. Controllare la console degli errori nel vostro IDE per capire cosa c'è di sbagliato in particolare.

I problemi più comuni sono:

  • Un carattere di escape nel vostro strings.xml, per esempio, invece di you're you\'re
  • mancante layout_width o layout_height tag di risorse di layout
  • Manca dichiarazioni di namespace
  • I nomi delle variabili che non sono supportati da Java, per esempio a causa di capitalizzazione o l'uso di spazi, trattini o altri caratteri non supportati
  • Qualsiasi altro tipo di errore di sintassi in XML
  • Verifica Console per le tematiche (L'immagine è allegata dove console è la definizione del problema perché R non sta generando nel progetto)

entrare descrizione dell

Quando ho incontrato questo problema a cancellare la cartella di generazione e verrà ricreato con tutti i file r

you will see at the top of your file it says import android.r or r.java i forget. you need to remove this line, clean the project, and rerun.
basically android uses R to reference items within your project. but when that import statement is there it overrides looking at your project directories and uses androids

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>

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.

Change the workspace to new directory and set its permissions such that it is available for everyone

In my case, i found an image file name containing an uppercase inside res/drawable. after changing the image name. it was solved and i could build the project

I faced this problem many times. The rule of thumb is to check your .xml files.
R.java is not generated when there is any issue in .xml file.

Simply click on

Build --> Clean Project

This worked for me

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top