加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

【我的Android进阶之旅】解决strings.xml格式化占位符错误: Mul

发布时间:2020-12-16 00:04:57 所属栏目:百科 来源:网络整理
导读:今天有一个Android新手使用strings.xml进行格式化的时候报了占位符错误, Multiple substitutions specified in non-positional format; did you mean to add the formatted=”false” attribute? ,问我该如何解决? 一、错误描述 具体错误描述如下所示: D:

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

一、错误描述

具体错误描述如下所示:

D:Code_For_Android_StudioMyGame2048appbuildintermediatesresmergeddebugvaluesvalues.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:AndroidStudiosdkbuild-tools23.0.2aapt.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://www.52php.cn/article/p-qpxpabkq-zq.html

  • http://www.52php.cn/article/p-ndmaeefn-yu.html

  • http://www.52php.cn/article/p-tmowrnui-bbu.html


作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://www.52php.cn/article/p-fkuxqsez-zw.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读