【我的Android进阶之旅】解决strings.xml格式化占位符错误: Multiple substitutions specified in non-positional format

简介: 今天有一个Android新手使用strings.xml进行格式化的时候报了占位符错误, Multiple substitutions specified in non-positional format; did you mean to add the f...

今天有一个Android新手使用strings.xml进行格式化的时候报了占位符错误, Multiple substitutions specified in non-positional format; did you mean to add the formatted=”false” attribute? ,问我该如何解决?

一、错误描述

具体错误描述如下所示:

D:\Code_For_Android_Studio\MyGame2048\app\build\intermediates\res\merged\debug\values\values.xml
Error:(16) Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?
Error:(16) Unexpected end tag string
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'F:\AndroidStudio\sdk\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 8.228 secs

这里写图片描述

二、问题原因

我看了下他的strings.xml的源代码,报错的那一行代码是这样写的:

这里写图片描述

<string name="test">游戏%s,作者:%s</string>

检查后发现是string.xml中的 %s 导致编译失败,应该把%s 改成%1$s的形式。

三、解决错误

<string name="test">游戏%s,作者:%s</string>

改成

<string name="test">游戏%1$s,作者:%2$s</string>

然后重新编译即可成功编译。


可参考文档:


作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/53027992

这里写图片描述

相关文章
|
8月前
|
XML 前端开发 Android开发
Android XML 布局基础(四)内外边距(margin、padding)
Android XML 布局基础(四)内外边距(margin、padding)
168 0
|
6月前
|
Android开发
android 错误 exported needs to be explicitly specified for Apps targeting Android 12
android 错误 exported needs to be explicitly specified for Apps targeting Android 12
|
7月前
|
编解码 网络协议 Android开发
Android平台RTMP|RTSP直播播放器功能进阶探讨
很多开发者在跟我聊天的时候,经常问我,为什么一个RTMP或RTSP播放器,你们需要设计那么多的接口,真的有必要吗?带着这样的疑惑,我们今天聊聊Android平台RTMP、RTSP播放器常规功能,如软硬解码设置、实时音量调节、实时快照、实时录像、视频view翻转和旋转、画面填充模式设定、解码后YUV、RGB数据回调等:
103 0
|
8月前
|
XML Java Android开发
#4,Android Studio Android程序结构 工程目录介绍 文件作用 运行配置文件AndroidManifest.xml
#4,Android Studio Android程序结构 工程目录介绍 文件作用 运行配置文件AndroidManifest.xml
|
8月前
|
XML Android开发 数据格式
Android Binary XML file line #50: Error inflating class androidx.cardview.widget.CardView 错误
Android Binary XML file line #50: Error inflating class androidx.cardview.widget.CardView 错误
49 0
|
8月前
|
XML 应用服务中间件 Android开发
Android的XML文件解析之PULL解析
Android的XML文件解析之PULL解析
|
8月前
|
XML Android开发 数据格式
Android XML 布局基础(八)帧布局 - GridLayout
Android XML 布局基础(八)帧布局 - GridLayout
90 0
|
8月前
|
XML Android开发 数据格式
Android XML 布局基础(七)帧布局 - FrameLayout
Android XML 布局基础(七)帧布局 - FrameLayout
54 0
|
8月前
|
XML Android开发 数据格式
Android XML 布局基础(六)相对布局 - RelativeLayout
Android XML 布局基础(六)相对布局 - RelativeLayout
100 0
|
8月前
|
XML Android开发 数据格式
Android XML 布局基础(五)线性布局 - LinearLayout
Android XML 布局基础(五)线性布局 - LinearLayout
84 0