【我的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

这里写图片描述

相关文章
|
3天前
|
API Android开发
Android高手进阶教程(十五)之---通过Location获取Address的使用!
Android高手进阶教程(十五)之---通过Location获取Address的使用!
|
7月前
|
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
|
8月前
|
编解码 网络协议 Android开发
Android平台RTMP|RTSP直播播放器功能进阶探讨
很多开发者在跟我聊天的时候,经常问我,为什么一个RTMP或RTSP播放器,你们需要设计那么多的接口,真的有必要吗?带着这样的疑惑,我们今天聊聊Android平台RTMP、RTSP播放器常规功能,如软硬解码设置、实时音量调节、实时快照、实时录像、视频view翻转和旋转、画面填充模式设定、解码后YUV、RGB数据回调等:
111 0
|
Web App开发 编解码 前端开发
Android | 音视频方向进阶路线及资源合集
但是系统相机和系统控件VideoView的局限性都是可定制型太差,系统相机的图像分辨率,视频码率以及VideoView的进度条等.
165 0
|
Android开发 Kotlin 移动开发
Android包体积优化(常规、进阶、极致)
Android包体积优化(常规、进阶、极致)
714 0
Android包体积优化(常规、进阶、极致)
|
Java Android开发 Kotlin
一些实用的Android进阶小技巧
主要是利用application获取唯一的全局实例context,使得我们在任何场景都可以获取context
78 0
一些实用的Android进阶小技巧
|
Android开发
Android Export时错误提示:Conversion to Dalvik format failed with error 1
Android Export时错误提示:Conversion to Dalvik format failed with error 1
69 0
Android Export时错误提示:Conversion to Dalvik format failed with error 1
|
前端开发 Android开发
Android进阶之绘制-自定义View完全掌握(四)
Android进阶之绘制-自定义View完全掌握(四)
87 0
Android进阶之绘制-自定义View完全掌握(四)