Android 构建项目问题:XML 片段出错,com.ctc.wstx.exc.WstxUnexpectedCharException

xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    :appxmlns="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    ...

</LinearLayout>
  • 在 Android 开发中,构建项目时,上述 XML 片段出错,出现如下错误信息

    Cause: com.ctc.wstx.exc.WstxUnexpectedCharException:
    Unexpected character ':' (code 58) (missing namespace prefix?)
    at [row,col {unknown-source}]: [5,5]). Check logs for more details.

问题原因
  1. :appxmlns 是非法的 XML 属性名,XML 属性名不能以冒号 : 开头,除非它是命名空间前缀,例如,xmlns:app

  2. 这里的 :appxmlns 被解析器当作一个带前缀的属性,但前缀为空,即冒号前没有内容,所以报错

    Unexpected character ':' (code 58) (missing namespace prefix?)

  3. 而且,这是一行重复且错误的命名空间声明,正确的命名空间已在上方声明

xml 复制代码
xmlns:app="http://schemas.android.com/apk/res-auto"
处理策略
  • 删除错误的那一行,保留正确的命名空间声明即可
xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    ...

</LinearLayout>
相关推荐
雨白1 小时前
C 语言字符串:从字符数组、指针到核心操作实战
android
Java小白笔记2 小时前
MySQL中存储过程大表分批删除历史数据
android·mysql·adb
aidou13142 小时前
Kotlin中沉浸式状态栏显示布局
android·kotlin·windowmanager·沉浸式状态栏·insetslistener·insetscompat·systembars
阿pin3 小时前
Android随笔-pipe是什么?
android·linux·pipe
帅次3 小时前
Android 高级工程师面试:Flow 与状态流 近1年高频追问 22 题
android·面试·职场和发展
雨季余静4 小时前
RustDesk Android APK 从零编译全步骤
android
辰合软件4 小时前
通达OA配置文件详解
android·adb
辰合软件4 小时前
通达OA目录结构与核心文件解析
android·数据库·oracle
通玄4 小时前
Jetpack Compose 入门系列(八):Compose 中的副作用处理
android