如何解决错误:“解析XML时出错:XML或文本声明不在实体的开头”
|| 我正在制作一个Sudoku Android应用程序,并且在main.xml下收到以下错误:\“错误:XML解析错误:XML或文本声明不在实体的开头\”任何帮助将不胜感激。这是我的代码。我在错误旁边加上了\'✗\' `✗<?xml version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout
xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:orientation=\"vertical\"
android:layout_height=\"fill_parent\"
android:layout_width=\"fill_parent\">
<TextView
android:layout_width=\"fill_parent\"
android:layout_height=\"wrap_content\"
android:text=\"@String/continue_label\"/>
<Button
android:id=\"@+id/continue_button\"
android:layout_width=\"fill_parent\"
android:layout_height=\"wrap_content\"
android:text=\"@string/continue_label\" />
<Button
android:id=\"@+id/new_button\"
android:layout_width=\"fill_parent\"
android:layout_height=\"wrap_content\"
android:text=\"@string/new_game_label\"/>
<Button
android:id=\"@+id/about_button\"
android:layout_Width=\"fill_parent\"
android:layout_height=\"wrap_content\"
android:text=\"@string/new_game_label\"/>
<Button
android:id=\"@+id/exit_button\"
android:layout_Width=\"fill_parent\"
android:layout_height=\"wrap_content\"
android:text=\"@string/exit_label\"/>
</LinearLayout>
`
解决方法
可能有两种情况-
情况1-如果在第一条语句之前有空白。
情况2-如果您不小心两次输入了相同的namepacing语句,即-?xml version = \“ 1.0 \” encoding = \“ utf-8 \”?
我做了一次,并在更正它后遇到了与您相同的错误,我的代码运行正常。希望这可以帮助
, 在某些情况下,如果文件顶部有两个XML版本(xml version = \“ 1.0 \” encoding = \“ utf-8 \”),则会出现此错误:
<?xml version=\"1.0\" encoding=\"utf-8\"?><?xml version=\"1.0\" encoding=\"utf-8\"?>
<shape xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:shape=\"rectangle\">
...
</shape>
只要保留一个就可以了
, 有一个间距,\2ѭ的这个\“✗\”前面
拿出来,它会起作用。
, 大多数情况下,错误“ XML解析错误”是由于“空空间”引起的。
这使JVM不能正确地增加Activity中的视图元素。因此,我建议...为了避免这种情况,而不是手动搜索空格,请执行以下操作:
步骤1. Ctrl + A->选择XML中的所有代码。
步骤2. Ctrl + I->自动以XML缩进代码
(**以上快捷键适用于Eclipse IDE)
, 我用xml看到的唯一问题是您写了两次
android:layout_Width
代替
android:layout_width
除此之外,您的xml看起来还不错。
就像Matthew Wilson建议的那样,请确保xml声明前没有任何内容
如果这样不起作用,请尝试创建一个新的xml文件(在Eclipse中,通过菜单文件>新建-> Android XML文件。)然后将现有xml部分的一部分添加为部分,并每次检查其是否仍然有效。这样,您可以查明问题的位置。
, 可能的原因之一可能是您在xml文件中的另一个名称空间..中声明了名称空间。例如
`
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<shape xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:shape=\"rectangle\" >
<corners
android:bottomLeftRadius=\"30dp\"
android:topLeftRadius=\"30dp\" />
<solid android:color=\"#CFCFCF\" />
<padding
android:bottom=\"0dp\"
android:left=\"0dp\"
android:right=\"0dp\"
android:top=\"0dp\" />
<size
android:height=\"60dp\"
android:width=\"130dp\" />
</shape>
</selector>
`
, 就我而言,在某些info.plist文件中,第一行中有一个空行会导致此问题...请检查info.plist中是否有多余的空行,如果有,请删除它。
有关更多信息:
https://github.com/ydkhatri/mac_apt/issues/16
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。