开发者

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.an开发者_如何转开发droid.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?


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.


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


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.


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


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.


Remove the semicolon after hello


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.


In my case I forgot to end my ConstrainLayout

</android.support.constraint.ConstraintLayout>

After that, everything started working correctly.


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜