【问题标题】:Unable to find reason- Error:(40) Error parsing XML: not well-formed (invalid token)无法找到原因 - 错误:(40) 解析 XML 时出错:格式不正确(无效令牌)
【发布时间】:2016-03-30 14:36:36
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.android.musicplayer.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/title"
    android:layout_centerHorizontal="true"
    android:id="@+id/textView"
    android:textSize="40sp"/>

 <Button
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:id="@+id/button"
     android:text=">>"/>
  <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_toRightOf="@id/button"
      android:id="@+id/button2"
      android:text="||"
      />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@id/button2"
        android:id="@+id/button3"
        android:text="<"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:id="@+id/button4"
        android:layout_toRightOf="@id/button3"
        android:text="||"
       />
    <SeekBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/button"
        android:id="@+id/seekBar"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/textView2"
        android:layout_above="@id/seekBar"
        android:layout_toLeftOf="@id/textView"
        android:layout_toStartOf="@id/textView" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/textView3"
        android:layout_above="@id/seekBar"
        android:layout_alignRight="@id/button4"
        android:layout_alignEnd="@id/button4" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Medium Text"
        android:id="@+id/textView4"
        android:layout_alignBaseline="@id/textView2"
        android:layout_alignBottom="@id/textView2"
        android:layout_centerHorizontal="true" />


</RelativeLayout>

我也遇到了一个错误: 错误:任务 ':app:processDebugResources' 执行失败。

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/dell/Android/Sdk/build-tools/23.0.2/aapt'' 完成非零退出值 1

【问题讨论】:

  • android:text="&lt;" 替换为 android:text="&amp;lt;" 或根据 IntelliJ Amiya 回答使用字符串资源

标签: android xml


【解决方案1】:

硬编码字符串“>,应该使用@string资源

知道了

这里有问题

 android:text="<"  
 android:text=">>"

你应该怎么做

android:text="@string/Your_String_Name" 

然后

 <?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="Your_String_Name">&lt;</string> // For < Sign 
</resources>

感谢https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

hardcoded string "row three", should use @string resource

【讨论】:

  • 写成文字看仔细@IntelliJ Amiya
  • 不,这是正确的,您必须在 strings.xml 中添加这些符号,而且为什么您使用符号来控制音乐播放控件而不是图像??
猜你喜欢
  • 1970-01-01
  • 2015-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-12
  • 1970-01-01
相关资源
最近更新 更多