Android 错误:";分析XML时出错:XML或文本声明不在实体的开头;
我正在制作一个数独Android应用程序,在main.xml下出现了以下错误:“错误:解析xml时出错:xml或文本声明不在实体的开头”如果您有任何帮助,我们将不胜感激。这是我的密码。我把✗' 错误旁边Android 错误:";分析XML时出错:XML或文本声明不在实体的开头;,android,eclipse,Android,Eclipse,我正在制作一个数独Android应用程序,在main.xml下出现了以下错误:“错误:解析xml时出错:xml或文本声明不在实体的开头”如果您有任何帮助,我们将不胜感激。这是我的密码。我把✗' 错误旁边 `✗<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orient
`✗<?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>
`✗
`我能看到的关于xml的唯一问题是,您已经编写了两次了
android:layout_Width
而不是
android:layout_width
除此之外,您的xml看起来还不错。
正如Matthew Wilson所建议的,确保xml声明前面没有任何内容
如果这不起作用,请尝试创建一个新的xml文件(在Eclipse中,通过菜单file>new->AndroidXML文件),然后将现有xml部件中的部件添加到部件中,每次检查它是否仍然有效。通过这种方式,您可以精确定位问题所在的位置。有一个间距,这个“✗"
把它拿出来就行了。可能有两种情况- 案例1-如果在第一条语句之前有一个空格 案例2-如果您不小心将同一名称空间语句放置了两次,即-?xml version=“1.0”encoding=“utf-8”
我做过一次,并且在纠正了它之后,遇到了与您相同的错误。我的代码运行良好。希望这对大多数情况下有所帮助,错误“错误解析XML”是由于“空白”。 这使得JVM无法正确膨胀活动中的视图元素。因此,我建议……为了避免这种情况,与其手动搜索空间,不如执行以下操作:- 步骤1.Ctrl+A->选择XML中的所有代码 步骤2.Ctrl+I->自动缩进XML中的代码
(**以上快捷方式适用于Eclipse IDE)在某些情况下,如果在我的文件顶部有两个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>
...
只需保留一个名称空间,就可以了其中一个可能的原因可能是您在xml文件中的另一个名称空间中声明了名称空间 `
`在我的例子中,在一些info.plist文件中,第一行中有一个空行导致了此问题……请检查info.plist是否有多余的空行,如果有,请将其删除 有关更多信息:
详细信息,详细信息,详细信息…我们需要详细信息。您可以编辑原始帖子,以包含尽可能多的必要/相关代码。编辑时,使用文本区域可用的格式化工具格式化代码。您的问题越清晰、越容易阅读,您将获得越多的帮助。我不太清楚代码的一部分是什么还有什么不是,但在“哦,对不起”之前你不能吃任何东西✗ 是要告诉你错误在哪里,但之前什么都没有。是的,可能是大写的W on about和exit按钮!哦,是的,我明白了,谢谢。但是我这里仍然有两个错误:不允许处理指令目标匹配“[xX][mM][lL]”。错误2:错误:解析XML时出错:不在entityProject clean开头的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>