【问题标题】:Cannot find reason why getting error "Error parsing XML: not well-formed(invalid token)"找不到出现错误“解析 XML 时出错:格式不正确(无效令牌)”的原因
【发布时间】:2014-04-23 01:33:26
【问题描述】:

出现错误:“解析 XML 时出错:格式不正确(无效令牌)”可能是由于相对布局未使用 '/>' 或 '>' 正确关闭引起的,但是,我根本找不到发生错误。也许我今天已经编码太久了,但希望有新思想的人可以很容易地为我发现它。谢谢。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/player_background">

    <!-- Player Header -->
    <LinearLayout
        android:id="@+id/player_header_bg"
        android:layout_width="fill_parent"
        android:layout_height="60dip"
        android:background="@layout/bg_player_header"
        android:layout_alignParentTop="true"
        android:paddingLeft="5dp"
        android:paddingRight="5dp">

        <!-- Song Title -->
        <TextView
            android:id="@+id/songTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="#04b3d2"
            android:textSize="16dp"
            android:paddingLeft="10dp"
            android:textStyle="bold"
            android:text="The Good, The Bad And The Ugly"
            android:layout_marginTop="10dp"/>

        <!-- Playlist button -->
        <ImageButton
            android:id="@+id/btnPlaylist"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:src="@drawable/btn_playlist"
            android:background="@null"/>
    </LinearLayout>

    <!-- Song Thumbnail Image -->
    <LinearLayout
        android:id="@+id/songThumbnail"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:gravity="center"
        android:layout_below="@id/player_header_bg">
        <ImageView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/adele"/>
    </LinearLayout>

    <!-- Player Footer -->
    <LinearLayout
        android:id="@+id/player_footer_bg"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:background="@layout/bg_player_footer"
        android:gravity="center">

        <!-- Player Buttons -->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:background="@layout/rounded_corner"
            android:paddingLeft="10dp"
            android:paddingRight="10dp">
            <!-- Previous Button -->
            <ImageButton
                android:id="@+id/btnPrevious"
                android:src="@drawable/btn_previous"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@null"/>
            <!-- Backward Button -->
            <ImageButton
                android:id="@+id/btnBackward"
                android:src="@drawable/btn_backward"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@null"/>
            <!-- Play Button -->
            <ImageButton
                android:id="@+id/btnPlay"
                android:src="@drawable/btn_play"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@null"/>
            <!-- Forward Button -->
            <ImageButton
                android:id="@+id/btnForward"
                android:src="@drawable/btn_forward"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@null"/>
            <!-- Next Button -->
            <ImageButton
                android:id="@+id/btnNext"
                android:src="@drawable/btn_next"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@null"/>
        </LinearLayout>
    </LinearLayout>

    <!-- Progress Bar/Seek bar -->
    <SeekBar
         android:id="@+id/songProgressBar"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_marginRight="20dp"
         android:layout_marginLeft="20dp"
         android:layout_marginBottom="20dp"
         android:layout_above="@id/player_footer_bg"
         android:thumb="@drawable/seek_handler"
         android:progressDrawable="@drawable/seekbar_progress"
         android:paddingLeft="6dp"
         android:paddingRight="6dp"/>

    <!-- Timer Display -->
    <LinearLayout
        android:id="@+id/timerDisplay"
        android:layout_above="@id/songProgressBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginBottom="10dp">
        <!-- Current Duration Label -->
        <TextView
            android:id="@+id/songCurrentDurationLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:textColor="#eeeeee"
            android:textStyle="bold"/>
        <!-- Total Duration Label -->
        <TextView
            android:id="@+id/songTotalDurationLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right"
            android:textColor="#04cbde"
            android:textStyle="bold"/>
    </LinearLayout>

    <!-- Repeat / Shuffle buttons -->
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/timerDisplay"
        android:gravity="center">
        <!-- Repeat Button -->
        <ImageButton
            android:id="@+id/btnRepeat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/btn_repeat"
            android:layout_marginRight="5dp"
            android:background="@null"/>

        <!-- Shuffle Button -->
         <ImageButton
            android:id="@+id/btnShuffle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/btn_shuffle"
            android:layout_marginLeft="5dp"
            android:background="@null"/>
    </LinearLayout>
</RelativeLayout>

已解决:Android SDK 对于您在 eclipse 中创建的 XML 文件的类型非常迂腐。即使我删除了默认代码,我还是选择了一个非布局 XML 文件,这就是问题所在。谢谢大家的回答。

【问题讨论】:

  • 我没有发现任何错误。 IDE 工作正常吗?
  • 我已尝试清理项目并重新启动 Eclipse,但仍然出现这些错误。很奇怪。
  • 在视觉工作室中没有错误
  • 您的 XML 签出,根据 Visual Studio。你确定你的一个背景 XML 没有反作用吗?
  • 我知道这很奇怪,但是为了让其他人更容易做到这一点,您可能希望在 24 小时内回答您自己的问题并将其标记为正确答案,以便人们更容易看到您的解决方案.

标签: android xml


【解决方案1】:

XML 文件有效并且对我有用。

您的 IDE 可能有问题。尝试清理您的项目并重建它。要在 Eclipse 中执行此操作,请单击“项目”->“清理”

这在过去为我解决了很多 XML 解析错误。

【讨论】:

    猜你喜欢
    • 2016-03-30
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多