【问题标题】:Error:(2) Error parsing XML: not well-formed (invalid token)错误:(2) 解析 XML 时出错:格式不正确(无效令牌)
【发布时间】:2015-11-27 06:20:54
【问题描述】:

我正在使用 Android Studio 编译sdk版本:-API 23:Android 6.0 (Marshmallow) 构建工具版本:-23.0.2

得到这个错误

错误:(2) 解析 XML 时出错:格式不正确(无效令牌)

错误:任务 ':app:processDebugResources' 执行失败。

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'E:\AndroidSdk\sdk\build-tools\23.0.2\aapt.exe'' 完成非零退出值 1

我的代码是

<?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

< TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Enter your number to be doubled."/>
< EditText
        android:id="@+id/inputNum"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        </EditText>

        < Button
            android:id="@+id/doubleme"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Double Me"/>
            </LinearLayout>

【问题讨论】:

  • 尝试删除第一行&lt;?xml version="1.0" encoding="utf-8"?&gt; ?

标签: android xml


【解决方案1】:

&lt; 字符和标签名称之间不应有任何空格,请使用此替换您的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:orientation="vertical">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enter your number to be doubled."/>

    <EditText
        android:id="@+id/inputNum"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <Button
        android:id="@+id/doubleme"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Double Me"/>
</LinearLayout>

【讨论】:

    猜你喜欢
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    相关资源
    最近更新 更多