开发者

Error: "Error parsing XML: XML or text declaration not at start of entity"

I am making a Sudoku Android app and I am getting the following errors under main.xml: "error: Error parsing XML: XML or text declaration not at start of entity" Any help would be appreciated. Here is my code. I put '✗' next to the error

  `✗<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@String/continue_label"/>

        <Button
            android:id="@+id/continue_button"
            android:layout_开发者_Go百科width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/continue_label" />

        <Button
            android:id="@+id/new_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/new_game_label"/>

        <Button 
            android:id="@+id/about_button"
            android:layout_Width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/new_game_label"/>

        <Button
            android:id="@+id/exit_button"
            android:layout_Width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/exit_label"/>
    </LinearLayout>

`


There can be two cases -

case 1 - If you have an empty space before the first statement.

case 2 - If you have accidently put the same namespacing statement twice ie - ?xml version="1.0" encoding="utf-8"?

I did it once and landed with the same error of yours after correcting it my code runs fine.


In some case, if you have two XML version ( xml version="1.0" encoding="utf-8" )at the top of my file, you will have this error :

<?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    ...

</shape>

Just keep one and it's ok


There is a spacing and this "✗" infront of <?xml version="1.0" encoding="utf-8"?>

Take that out and it would work.


Most of the time, the error "Error Parsing XML" is due to "Empty Space". This made JVM to NOT properly inflate the view-elements in Activity. So, i recommend that....in order to avoid that, instead of manually searching the spaces, do following:-

Step 1. Ctrl +A -> select all code in XML.

Step 2. Ctrl+ I -> Automatic Indent the Code in XML

(** Above shortcuts are for Eclipse IDE)


The only problem I can see with your xml is that twice you've written

android:layout_Width

instead of

android:layout_width 

Other than that your xml looks fine. Like Matthew Wilson suggested, make sure there is nothing in front of the xml declaration

If this doesn't work try creating an new xml file (in Eclipse via menu File > New -> Android XML File.) Then add your parts of your existing xml part for part and each time check if it is still valid. This way you can pinpoint the location of your problems.


in my case, in some info.plist files , there is an empty line in first line that cause this problem ... check info.plist for extra empty line and if there is, delete it .

for more info: https://github.com/ydkhatri/mac_apt/issues/16


one of the possible reason could be that you have declared namespace inside another namespace.. in the xml file. for example `

  <?xml version="1.0" encoding="utf-8"?>
     <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <?xml version="1.0" encoding="utf-8"?>
         <shape xmlns:android="http://schemas.android.com/apk/res/android"
           android:shape="rectangle" >

           <corners
              android:bottomLeftRadius="30dp"
              android:topLeftRadius="30dp" />

         <solid android:color="#CFCFCF" />

         <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp" />

       <size
        android:height="60dp"
        android:width="130dp" />

     </shape>
  </selector>

`

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜