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>
相关推荐
flower_drop7 小时前
基于 WebUSB 与 CDP:在浏览器端实现 Android 设备通信与无证书抓包实践
android·chrome·测试工具·adb·bug·edge浏览器
撩得Android一次心动8 小时前
Jetpack Compose 知识点整理1【个人用】
android·学习·kotlin·android jetpack·compose
ForteScarlet10 小时前
Kotlin 2.4.20 现已发布,新特性多不多?
android·java·开发语言·开源·kotlin·jetbrains
方白羽11 小时前
Android Studio 自动国际化插件:SmartI18n
android·android studio·intellij idea
码农coding14 小时前
android12 状态栏图标的加载流程
android
hai_android15 小时前
Kotlin 协程作用域源码剖析
android·kotlin
Yeyu15 小时前
Android 画中画(PiP)小窗播放:怎么做、以及它到底是怎么工作的
android
千里马学框架15 小时前
安卓系统性能优化高级实战开发专题--开机,app冷启动优化
android·智能手机·性能优化·framework·性能·开机优化·app冷启动优化
律宏阔16 小时前
Android 手机通过 adblib 使用 ADB Wi-Fi 控制 Android 9 开发板
android
律宏阔16 小时前
Android App 里实现开机动画替换
android