2013-05-19 13 views
5

In questo file sono i miei layout i seguenti errori vengono visualizzati in questo codiceErrore: Nessun risorsa trovato che corrisponde al nome dato

error: Error: No resource found that matches the given name (at 'id' with value '@id/question_text_view'). 
error: Error: No resource found that matches the given name (at 'id' with value '@id/next_button'). 

questo è il file di layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@id/question_text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="24dp" 
     /> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:orientation="horizontal" > 
     <Button 
      android:id="@+id/true_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/true_button" 
     /> 
     <Button 
      android:id="@+id/false_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/false_button" 
     /> 
    </LinearLayout> 
     <Button 
     android:id="@id/next_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/next_button" 
     /> 
</LinearLayout> 

Questo è il mio stringhe. xml

<?xml version="1.0" encoding="utf-8"?> 
    <resources> 

     <string name="app_name">GeoQuiz</string> 
     <string name="true_button">True</string> 
     <string name="false_button">False</string> 
     <string name="correct_toast">Correct</string> 
     <string name="next_button">Next</string> 
     <string name="incorrect_toast">Incorrect</string> 
    <string name="action_settings">Settings</string> 
    <string name="question_founder">Frank Reed Horton Founded APO on december 25 1947</string> 
    <string name="question_chief">Willy Wonka was known as a cheif</string> 
    <string name="question_lady">The first lady that became president in APO was Mary Katz</string> 
    <string name="question_president">Our current President of the Delta Rho chapter is john dolan</string> 
<string name="question_alphabets">Alpha, Beta, Gamma, Delta, Epsilon, Eta, Zeta</string> 
</resources> 

so che c'è sapere question_text_view sulle corde, ma ho fatto un allineamento nella mia attività che prende tutte le domande mQuestionTextView = (TextView) findViewById (R.id.question_text_view); int question = mQuestionBank [mCurrentIndex] .getQuestion(); mQuestionTextView.setText (domanda); mQuestionBank è una matrice di tutte le domande che mi chiedo getQuestion() è il mio metodo getter per ottenere la questione

e il secondo errore per next_button io non so cosa ho fatto di sbagliato in quanto ho inserito sul strings.xml Qualcuno può per favore aiutarmi

+1

android: id = "@ id/question_text_view" dovrebbe essere Android: id = "@ + id/question_text_view" stesso pulsante Android : id = "@ + id/next_button" – Raghunandan

+1

vedi [Più tipi di risorse] (h ttp: //developer.android.com/guide/topics/resources/more-resources.html#Id) per la definizione dell'ID per Views in xml. dovrai usare '' invece di '' per inserire l'id nel file strings.xml o puoi creare un file separato come ids.xml –

risposta

7

android: id = "@ id/question_text_view" dovrebbe essere Android: id = "@ + id/question_text_view" stessa per il tasto Android: id = "@ id/next_button" dovrebbe essere Android: id = "@ + id/next_button"

TextView

<TextView 
    android:id="@+id/question_text_view" // missing + in your xml code 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="24dp" 
    /> 

pulsante

<Button 
    android:id="@+id/next_button" // missing + in your xml code 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/next_button" 
    /> 

ID

Qualsiasi oggetto Vista può avere un ID intero associato ad esso, per identificare in modo univoco la Vista all'interno dell'albero. Quando l'applicazione è compilata, questo ID viene referenziato come un numero intero, ma l'ID viene generalmente assegnato nel file XML del layout come una stringa, nell'attributo id. Questo è un attributo XML comune a tutti gli oggetti View (definito dalla classe View) e lo userai molto spesso. La sintassi per un ID, all'interno di un tag XML è:

L'at-simbolo (@) all'inizio della stringa indica che il parser XML dovrebbe analizzare ed espandere il resto della stringa ID e identificarlo come un Risorsa ID. Il simbolo più (+) indica che si tratta di un nuovo nome di risorsa che deve essere creato e aggiunto alle nostre risorse (nel file R.java).

Nel tuo caso l'id del pulsante è Android: id = "@ id/next_button". Stai facendo riferimento all'ID risorsa Android (presume). Questo non esiste. È lo stesso per la visualizzazione del testo. Quindi ottieni l'errore Risorsa non trovata.

Per ulteriori informazioni consulta sul link qui sotto

http://developer.android.com/guide/topics/ui/declaring-layout.html

0

Si dovrebbe fare attenzione con l'ID delle viste. Nella tua TextView e anche nella tua vista Button stai dimenticando il '+' nell'attributo ID. Per quanto ne so tu cerchi di riferirti a un'altra vista con l'ID. Se si utilizza il '+' si crea un nuovo ID per quella vista.

versione fissa:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/question_text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="24dp" 
     /> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:orientation="horizontal" > 
     <Button 
      android:id="@+id/true_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/true_button" 
     /> 
     <Button 
      android:id="@+id/false_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/false_button" 
     /> 
    </LinearLayout> 
     <Button 
     android:id="@+id/next_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/next_button" 
     /> 
</LinearLayout> 
0

forse percorso della cartella è troppo lungo come la mia "E: \ Project \ mobile \ SixworldGit \ sixworld \ progetti \ sixworld \ SW_Vietnam \ 2.3. 2.0.20160711_Android_MoboSDKAll_lucgioi_20160711_1805 \ 2.3.2.0.20160711_Android_MoboSDKAll \ MoboSDK \ riferimento \ MoboSDKAll \ res \ drawable"

Problemi correlati