Vinnie2981178 Vinnie2981178 - 6 months ago 78
Android Question

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

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.

Answer

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.