2013-04-17 5 views
0

Je viens de commencer le tutoriel du débutant sur Android et je reçois 4 erreurs lors de la compilation, même si le code est essentiellement copié à partir de la page Web et j'ai suivi toutes les étapes. Les erreurs sont les suivantes:android débutant tutoriel Erreur analyse syntaxique XML

  • Le type d'élément "LinearLayout" doit être suivi des spécifications d'attribut, ">" ou "/>". activity_main.xml/test/res/ligne mise en page 6 Format XML Android problème
  • R ne peut pas être résolu à une variable MainActivity.java/test/src/com/example/ligne de test 12 Java Problème
  • R ne peut pas être résolu à une variable MainActivity.java/test/src/com/exemple/ligne de test 19 Java Problème
  • erreur: Erreur d'analyse XML: pas bien formé (jeton invalide) activity_main.xml/test/res/layout line 6 Problème AAPT Android ]

Voici le code: activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 

     <EditText android:id="@+id/edit_message" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:hint="@string/edit_message" 
      android:layout_weight="1" /> 

     <Button android:layout_width="wrap content" 
      android:layout_height="wrap_content" 
      android:text="@string/button_send" /> 

    </LinearLayout> 

MainActivity.java

package com.example.test; 

    import android.os.Bundle; 
    import android.app.Activity; 
    import android.view.Menu; 

    public class MainActivity extends Activity { 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 
     } 


     @Override 
     public boolean onCreateOptionsMenu(Menu menu) { 
      // Inflate the menu; this adds items to the action bar if it is present. 
      getMenuInflater().inflate(R.menu.main, menu); 
      return true; 
     } 

    } 

J'ai cherché partout, tout essayé et il va toujours pas, donc c'est mon dernier espoir. Merci!

+1

Une bonne habitude à développer est l'utilisation d'espaces blancs. Voyez comment j'ai édité votre exemple et comment cela rend l'erreur beaucoup plus facile à voir? – Simon

+0

En fait, j'ai utilisé des espaces blancs à l'origine, mais j'avais peur que ce soit l'erreur. Merci pour le conseil! – user2291950

Répondre

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 
    <EditText android:id="@+id/edit_message" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:hint="@string/edit_message" 
     android:layout_weight="1" /> 
    <Button android:layout_width="wrap content" 
     android:layout_height="wrap_content" 
     android:text="@string/button_send" /> 
</LinearLayout> 

Copier ce, projet propre et géré. Vous n'avez pas terminé le tag LinearLayout avant EditText.

+0

Merci beaucoup, corrigé le problème! – user2291950

2

Votre étiquette LinearLayout doit être fermée.

i.e.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" <-- close here 

comme celui-ci

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" > 
+0

Marquer comme ça. – Akyl

+0

Merci beaucoup, totalement détourné mon attention – user2291950