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>
相关推荐
delta_hell2 小时前
【阅读源码-Android】动画之AnimatorSet--2
android·源码·animatorset
叶辞树5 小时前
Android CLI
android
我命由我123458 小时前
Android 开发问题:unexpected element <service> found in <manifest>
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
程思扬8 小时前
Android ANR实战排查:主线程SystemClock.sleep导致页面启动偶现无响应
android·笔记
码农coding8 小时前
android12 InputManagerService分析之输入事件如何回到应用层
android
zhangguojia79 小时前
从一个窗口覆盖问题出发,理解 Android Window 的层级与权限
android
古法安卓11 小时前
Android-SELinux 策略调试实战:从 AVC 日志到策略修复
android·java·android studio
Dovis(誓平步青云)12 小时前
DevEco Studio 6.1.1 Windows 安装实录:从下载校验到首次启动
android·开发语言·数据库·人工智能·windows·harmonyos
Zender Han12 小时前
Flutter 自适应(Adaptive)与响应式(Responsive)设计实践:官方推荐方案详解
android·flutter·ios
我命由我1234512 小时前
Android 开发问题:TopAppBar 和 topAppBarColors API is experimental...
android·java·java-ee·kotlin·android studio·android jetpack·android-studio