Ahnaf
Ahnaf

Reputation: 159

How to fix Error Parsing XML in android development?

I am trying to learn android development.As a learning exercise i am trying to develop a simple calculator app. My UI is ready it renders perfectly in android studio but when ever i am trying to run the app the android studio is giving me

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

from the help of internet i found it can happen if i have any spelling mistake. but i could not find any in my code. I rebuilded the project but the error still exists. my code is below please help me to find where i m going wrong.

<?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>

Upvotes: 1

Views: 890

Answers (1)

HelloSadness
HelloSadness

Reputation: 955

You have 2 problems.
First one : remove white space in textColor attribute :

<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"/>

Second one is :

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

You should extract the String << causing an issue at compilation. extract string resource like so :

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

Then in strings.xml (/res/values/strings.xml) add the created resource :

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

Upvotes: 1

Related Questions