您的位置:首页 > 移动开发 > Android开发

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

2016-11-03 23:34 766 查看
今天有一个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/16804049

http://blog.csdn.net/xiaoyaovsxin/article/details/8450056

http://blog.csdn.net/jabony/article/details/29577203

作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!

转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/53027992

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐