我正在使用eclipse来编写Android应用程序,我停了下来。我尝试关闭我的代码
<?xml version="1.0" encoding="utf-8"?>
但是我不断收到错误消息
"与"[xX][mM][lL]"匹配的处理指令目标不是 允许。
代码如下:
<?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"?>
我犯了什么错误吗?如果我这样做了,请通知我。
请确保在xml文件的开头<?xml
之前不应该有任何字符。希望这对你有帮助
是的,该 xml 列表有几个错误(假设它只是一个文件)。
删除这些字符串资源,并将它们放在项目res/values
文件夹中自己的strings.xml
文件中。此外,字符串.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>
这不是错误,但您可能希望向这些字符串资源添加一些可能的文本标签,如下所示:
<?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>
不要忘记用以下命令关闭您的线性布局:
</LinearLayout>
删除两个 requestFocus 中的一个,我假设每个布局应该只有一个(再次假设,您只打算向我们显示一个文件而不是多个文件)。
<requestFocus />
并删除最后一行(这是Eclipse抱怨的内容):
<?xml version="1.0" encoding="utf-8"?>
您确实保留了 xml 文件第一行中的一个,但从最后一行中删除了那个,因为这种类型的指令不会关闭。
让我知道这是否解决了您的所有问题。我不能确定它确实如此,因为我没有花时间打开另一台计算机并使用Eclipse进行检查。
是的,<?xml
之前不应该有任何字符..甚至不是空白字符..我有同样的问题..解决了..
1)在XML文件中使用或标记时,请确保您的代码不包含任何未声明的变量(在字符串.xml文件中)
2) 确保"R.java"文件反映了使用的所有变量。
3) 重新构建项目并进行验证。
打开清单.xml按 ctrl+A
然后按 ctrl+I
。它将自动格式化您的清单.xml。
如果语法正确并且仍然收到此错误,则只需打开 xml 文件并右键单击并选择验证。
1.确保您已写入清单文件的开头...2.确保文件前不应有任何字符...