Usama Sarwar
Usama Sarwar

Reputation: 9020

error: Error parsing XML: not well-formed (invalid token) ...?

I am working on an application, with following XML. but whenI try to clean/build my project the following error occurs:

"error: 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"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello";
/>
</LinearLayout>

What does it possibly mean?

Upvotes: 49

Views: 250244

Answers (10)

Dalvinder Singh
Dalvinder Singh

Reputation: 1083

I had same problem. you can't use left < arrow in text property like as android:text="< Go back" in your xml file. Remove any < arrow from you xml code.

Hope It will helps you.

Upvotes: 12

Pedram
Pedram

Reputation: 2621

I had the same problem. In my case, even though I have not understood why, the problem was due to & in one of the elements like the following where a and b are two tokens/words:

<s> . . . a & b . . . </s>

and to resolve the issue I turned my element's text to the following:

<s> . . . a and b . . . </s>

I thought it might be the case for some of you. Generally, to make your life easier, just go and read the character at the index mentioned in the error message (line:..., col:...) and see what the character is.

Upvotes: 2

Vijay
Vijay

Reputation: 1388

Problem is that you are doing something wrong in XML layout file

android:text=" <- Go Back" // this creates error
android:text="Go Back" // correct way

Upvotes: 0

Michael Fahim
Michael Fahim

Reputation: 19

I tried everything on my end and ended up with the following.

I had the first line as:

<?xmlversion="1.0"encoding="utf-8"?>

And I was missing two spaces there, and it should be:

<?xml version="1.0" encoding="utf-8"?>

Before the version and before the encoding there should be a space.

Upvotes: 0

Wiktor Kalinowski
Wiktor Kalinowski

Reputation: 79

In my case I forgot to end my ConstrainLayout

</android.support.constraint.ConstraintLayout>

After that, everything started working correctly.

Upvotes: 0

Alan Kinnaman
Alan Kinnaman

Reputation: 926

To solve this issue, I pasted my layout into https://www.xmlvalidation.com/, which told me exactly what the error was. As was the case with other answers, my XML had < in a string.

Upvotes: 9

Rock Lee
Rock Lee

Reputation: 9576

I had this problem, and when I had android:text="< Go back" it had the correct syntax highlighting, but then I realized it's the < symbol that is messing everything up.

Upvotes: 50

Vincent Thacker
Vincent Thacker

Reputation: 393

Remove the semicolon after hello

Upvotes: 2

Julian Suarez
Julian Suarez

Reputation: 4521

Verify that you don't have any spaces or tabs before

<?xml version="1.0" encoding="utf-8"?>

also refresh and clean your project in eclipse.

I get this error every now and then and the above suggestions fix the issue 99% of the time

Upvotes: 9

Blundell
Blundell

Reputation: 76564

It means there is a compilation error in your XML file, something that shouldn't be there: a spelling mistake/a spurious character/an incorrect namespace.

Your issue is you've got a semicolon that shouldn't be there after this line:

  android:text="@string/hello";

Upvotes: 47

Related Questions