ERROR:The processing instruction target matching “[xX][mM][lL]” is not allowed [duplicate]

匿名 (未验证) 提交于 2019-12-03 08:35:02

问题:

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.

回答1:

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.



回答2:

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



回答3:

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



回答4:

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.



回答5:

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



回答6:

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



回答7:

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!