2017-07-04 7 views
0

Ich lerne Android-Entwicklung und konfrontiert Probleme beim Bau des Projekts. Ich mache einen Rechner App:Fehler beim Parsen von XML: nicht wohlgeformt (ungültiges Token) in Android

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:layout_alignParentBottom="true" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.palakjain.simplecalculator.MainActivity"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="100dp" 
     android:layout_marginBottom="20dp" 
     android:id="@+id/textView" /> 

     <!--<Button 
      android:id="@+id/btnErase" 
      android:text="<-" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/>--> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/btnClear" 
      android:text="C" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btnPercentage" 
      android:text="%" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btnDivide" 
      android:text="/" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <Button 
      android:id="@+id/btn1" 
      android:text="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btn2" 
      android:text="2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btn3" 
      android:text="3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btnMul" 
      android:text="X" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout2" 
     android:layout_below="@+id/linearLayout"> 

     <Button 
      android:id="@+id/btn4" 
      android:text="4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btn5" 
      android:text="5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btn6" 
      android:text="6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btnSub" 
      android:text="-" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout"> 

     <Button 
      android:id="@+id/btn7" 
      android:text="7" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btn8" 
      android:text="8" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btn9" 
      android:text="9" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btnAdd" 
      android:text="+" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <Button 
      android:id="@+id/btnPoint" 
      android:text="." 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btn0" 
      android:text="0" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/btnEquals" 
      android:text="=" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 

</LinearLayout> 

Dies ist, was ich in meiner XML-Datei gemacht habe, und ich bin nicht in der Lage, herauszufinden, was falsch ist. Freundlich helfen.

+0

Veröffentlichen Sie Ihr vollständiges Layout xml und logcat. – FAT

+1

Ihr root lineares Layout ist nicht geschlossen. –

+0

Scheint, dass Ihr Layout in Ordnung ist. Kannst du bitte deine MainActivity.java posten? – FAT

Antwort

0

Verwenden Attribut android:layout_width="wrap_content"-btnClear statt match_parentbtnPercentage und btnDivide auf dem Bildschirm zu zeigen.

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <Button 
     android:id="@+id/btnClear" 
     android:text="C" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <Button 
     android:id="@+id/btnPercentage" 
     android:text="%" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <Button 
     android:id="@+id/btnDivide" 
     android:text="/" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

Schließlich Clean und Rebuild Ihr Projekt und Run wieder.

UPDATE:

Fehler bei der Analyse XML: nicht wohlgeformt (ungültiges Token) in Android

Ich denke, das Problem aufgrund android:text="<-" auftritt. Wenn Sie "<-" als Text auf Button zeigen wollen, dann Code unten verwenden:

<Button 
    android:id="@+id/btnClear" 
    android:text="&lt;-" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

FYI, hier &lt; repräsentiert <. Hoffe, das wird funktionieren ~

+0

@Palak Jain: Danke für die Annahme meiner Antwort. Wenn meine Antwort nützlich erscheint, hoffe ich, dass Sie eine Stimme abgeben werden. Danke im Voraus :) – FAT

Verwandte Themen