1

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>

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

4 Comments

thanks.it solved the problem. how to know which line is causing xml parsing error. i m a java guy. trying to learn android. is there any IDE which will help me finding xml errors?
@Ahnaf Android Studio should help. The linter typically detects the issues.
wen through whole XML, +1 :P
@cricket_007 .. in this case android studio was not showing any errors in any line,... thats why i got confused ... there was no red line in xml and it was rendering fine.. error came up whenever ran the app.. anyway error resolved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.