问题
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?
回答1:
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";
回答2:
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.
回答3:
I had same problem. you can't use left <
arrow in text property like as android:text="< Go to back"
in your xml file. Remove any <
arrow from you xml code.
Hope It will help you.use
回答4:
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
回答5:
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.
回答6:
Remove the semicolon after hello
回答7:
In my case I forgot to end my ConstrainLayout
</android.support.constraint.ConstraintLayout>
After that, everything started working correctly.
回答8:
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 though 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.
回答9:
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.
来源:https://stackoverflow.com/questions/7089718/error-error-parsing-xml-not-well-formed-invalid-token