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

发布时间:2026/7/7 18:38:34

Android 构建项目问题:XML 片段出错,com.ctc.wstx.exc.WstxUnexpectedCharException ?xml version1.0 encodingutf-8?LinearLayoutxmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/tools:appxmlnshttp://schemas.android.com/apk/res-autoandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationvertical.../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.问题原因:appxmlns是非法的 XML 属性名XML 属性名不能以冒号:开头除非它是命名空间前缀例如xmlns:app这里的 :appxmlns 被解析器当作一个带前缀的属性但前缀为空即冒号前没有内容所以报错Unexpected character : (code 58) (missing namespace prefix?)而且这是一行重复且错误的命名空间声明正确的命名空间已在上方声明xmlns:apphttp://schemas.android.com/apk/res-auto处理策略删除错误的那一行保留正确的命名空间声明即可?xml version1.0 encodingutf-8?LinearLayoutxmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationvertical.../LinearLayout

相关新闻