2016-11-12 150 views
1

我想学习Android开发。作为一个学习练习,我正在尝试开发一个简单的计算器应用程序。我的UI就绪时,它完美地呈现在Android Studio中,但是当过我试图运行应用程序的机器人工作室给我如何解决在android开发中解析XML错误?

Error:(189) Error parsing XML: not well-formed (invalid token)

从互联网的帮助下,我发现,如果我有任何的拼写错误,它可能发生。但我在代码中找不到任何内容。我重建了该项目,但错误仍然存​​在。我的代码在下面,请帮我找到我哪里错了。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.ahnaf.awsomecalc.MainActivity" 
    android:background="#373D4D"> 


    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="73dp" 
     android:background="#7069F2"> 
     <TextView 
      android:id="@+id/result" 
      android:text="Result" 
      android:textColor="#FFFFFF" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:gravity="right" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="73dp"> 
     <TextView 
      android:id="@+id/number" 
      android:text="Number" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="right" 
      android:textColor=" #373D4D" 
      android:background="#FFFFFF"/> 
    </LinearLayout> 


    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#373D4D"> 

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

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

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

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

     <Button 
      android:text="*" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/multiply" 
      android:layout_weight="1" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#373D4D"> 
     <Button 
      android:text="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/one" 
      android:layout_weight="1" /> 

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

     <Button 
      android:text="3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/three" 
      android:layout_weight="1" /> 
    </LinearLayout> 



    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#373D4D"> 
     <Button 
      android:text="4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/four" 
      android:layout_weight="1" /> 
     <Button 
      android:text="5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/five" 
      android:layout_weight="1" /> 

     <Button 
      android:text="6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/six" 
      android:layout_weight="1" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#373D4D"> 

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

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

     <Button 
      android:text="9" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/nine" 
      android:layout_weight="1" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#373D4D" 
     > 
     <Button 

      android:text="." 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/dot" 
      android:layout_weight="1" /> 

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

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

</LinearLayout> 

回答

1

您有2个问题。
第一招:在textColor属性中删除空格:

<TextView 
      android:id="@+id/number" 
      android:text="Number" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="right" 
      android:textColor="#373D4D" 
      android:background="#FFFFFF"/> 

第二个是:

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

你应该提取字符串<<在编译造成的问题。提取字符串资源,像这样:

<Button 
     android:text="@string/yourstring" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/curr" 
     android:layout_weight="1" /> 

然后在strings.xml(/res/values/strings.xml)添加创建的资源:

<string name="yourstring"><![CDATA[<<]]></string> 
+0

thanks.it解决了这个问题。如何知道哪一行导致xml解析错误。我是一个java的家伙。试图学习android。有没有任何IDE可以帮助我发现XML错误? – Ahnaf

+0

@Annaf Android Studio应该会有所帮助。棉绒通常检测问题。 –

+0

文通过整个XML,+1:P –