Java ERROR: 不允许匹配“[xX][mM][lL]”的处理指令目标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19918455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 21:18:38  来源:igfitidea点击:

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

javaandroidxmleclipse

提问by Vinnie2981178

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

我正在使用 eclipse 编写一个 android 应用程序,但我停下来了。我尝试关闭我的代码

<?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."

“不允许匹配“[xX][mM][lL]”的处理指令目标。”

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.

我犯了什么错误吗?如果我这样做了,请通知我。

采纳答案by Stephan Branczyk

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

是的,那个 xml 列表有几个错误(假设它只是一个文件)。

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

删除这些字符串资源并将它们strings.xml放在项目res/values文件夹内的自己的文件中。此外,strings.xml 文件也应该以它自己的开头<?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:

</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 之一,我认为每个布局应该只有一个(再次假设,您只想向我们展示一个文件而不是多个文件)。

<requestFocus />

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

并删除最后一行(这就是 Eclipse 所抱怨的):

<?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.

您确实从 xml 文件的第一行保留了那个,但是从最后一行删除了那个,因为该类型的指令不会关闭。

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.

让我知道这是否解决了您的所有问题。我不能确定它确实如此,因为我没有花时间打开我的另一台计算机并检查 Eclipse。

回答by Shilpa

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

1) 在 XML 文件中使用或标记时,请确保您的代码不包含任何未声明的变量(在 string.xml 文件中)

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

2) 确保“R.java”文件反映了所有使用的变量。

3) Re-Build your project and verify.

3)重新构建您的项目并验证。

回答by Umer Farooq

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

请确保<?xml在 xml 文件的开头之前不应该有任何字符。希望能帮到你

回答by Chetan Nellekeri

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

是的,之前<?xml不应该有任何字符.. 甚至没有空白字符.. 我有同样的问题.. 得到解决..

回答by Faisal Naseer

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

开放的manifest.xml按ctrl+A然后ctrl+I。它会自动格式化您的 manifest.xml。

回答by Mukunda Jois

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

如果语法正确并且您仍然收到此错误,则只需打开 xml 文件并右键单击并选择验证。

回答by Saroj

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

1.确保您已在清单文件的开头写入... 2.确保文件前不应有任何字符...