14

I am using eclipse to program an android app and i came to a halt. I tried closing my code with

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

But I keep getting the error message

"The processing instruction target matching "[xX][mM][lL]" is not allowed."

Here's the code:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

<EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="text" >
        <requestFocus />

</EditText>  

<resources>
    <string android:name="app_name"></string>
    <string android:name="edit_message"></string>
    <string android:name="button_send"></string>
    <string android:name="action_settings"></string>
    <string android:name="title_activity_main"></string>
</resources>

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send" />

<EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="text" >
        <requestFocus />

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

Did I make any mistakes? If I did, please inform me.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
c.dasa
  • 162
  • 1
  • 1
  • 9

7 Answers7

17

Please make sure there should not any character before <?xml at the start of xml file. hope this will help you

UeliDeSchwert
  • 1,146
  • 10
  • 23
Umer Farooq
  • 221
  • 1
  • 4
  • 14
  • I am getting this exception mentioned in the description, but it happens only first time.. next time I try to parse it everything is fine.. how to resolve so that even first time I should not get it – praveen_mohan Sep 25 '14 at 09:13
11

Yes, that xml listing has several mistakes (assuming it's meant to be only one file).

Remove those string resources and place them in their own strings.xml file inside your project's res/values folder. Furthermore, that strings.xml file should also start with its own <?xml version="1.0" encoding="utf-8"?>

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string android:name="app_name"></string>
<string android:name="edit_message"></string>
<string android:name="button_send"></string>
<string android:name="action_settings"></string>
<string android:name="title_activity_main"></string>
</resources>

This is not an error, but you may want to add some possible text labels to those string resources like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string android:name="app_name">My Application Name</string>
<string android:name="edit_message"></string>
<string android:name="button_send">Send</string>
<string android:name="action_settings"></string>
<string android:name="title_activity_main"></string>
</resources>

Don't forget to close your LinearLayout with:

</LinearLayout>

Remove one of the two requestFocus, I would assume that you should only have one per layout (assuming that again, you only meant to show us only one file and not multiple files).

<requestFocus />

And remove that last line (that is what Eclipse is complaining about):

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

You do keep the one from the very first line of your xml file, but you remove the one from the last line, because that type of directive doesn't close.

Let me know if this fixed all your problems. I can't be sure it did because I didn't take the time to open my other computer and check with Eclipse.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
  • Thanks for the reply. I will change the code and see if it works. – c.dasa Nov 12 '13 at 22:19
  • Hi.Unfortunately I am still getting errors when I add the closing to the linear layout tab. I get this message "Element type "LinearLayout" must be followed by either attribute specifications, ">" or "/>". I would appreciate any help I can get. Thank you. – c.dasa Nov 12 '13 at 22:46
  • Remove xmlns:tools="http://schemas.android.com/tools". Keep only the one that starts with xmlns:android= (If you still get the same error, please post your last line on here as a comment.) – Stephan Branczyk Nov 13 '13 at 05:22
  • Hi. Unfortunately I am still getting the same error. Here's my Linear Layout code: – c.dasa Nov 13 '13 at 23:30
3

Yes, There should not be any character before <?xml.. Not even the blank character.. I had the same problem.. got resolved..

Chetan Nellekeri
  • 300
  • 2
  • 16
0

1) When using or tag in XML file make sure your code does not contain any undeclared variables (in the string.xml file)

2) Make sure the "R.java" file reflects all the variables used.

3) Re-Build your project and verify.

Shilpa
  • 217
  • 4
  • 14
0

Open manifest.xml press ctrl+A then ctrl+I . It will auto format your manifest.xml.

Faisal Naseer
  • 4,110
  • 1
  • 37
  • 55
0

If syntax is correct and if you still getting this error then just Open the xml file and right click and select validate.

0

1.Make sure you have written on the starting of the manifest file... 2.make sure there shouldn't any character before file...

Saroj
  • 1