android .string.xml使用String.format出现的问题
2017-04-15 22:52
555 查看
今天大篇的粘贴arrays.xml中出现了这个问题:
Type error:
Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?
对应的代码是:
解决办法是:
1 使用%%或\%,如:
2 添加 formatted="false" 属性
这个错误和ADT的版本有关,旧版本不会出现这个提示。
更新修正:
用上面两种方法,会使得字符串丧失格式化的能力(比如使用 getResource().getString(String,Object...)这个方法),保持格式化字符串的做法,可参考:http://blog.csdn.net/ganggang1st/article/details/6804086,修改如下:
Type error:
Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?
对应的代码是:
<string name="template_user_agent">"%s/%s (Linux; Android)"</string>
解决办法是:
1 使用%%或\%,如:
<string name="template_user_agent">"%%s/%%s (Linux; Android)"</string>
2 添加 formatted="false" 属性
<string name="template_user_agent" formatted="false">"%s/%s (Linux; Android)"</string>
这个错误和ADT的版本有关,旧版本不会出现这个提示。
更新修正:
用上面两种方法,会使得字符串丧失格式化的能力(比如使用 getResource().getString(String,Object...)这个方法),保持格式化字符串的做法,可参考:http://blog.csdn.net/ganggang1st/article/details/6804086,修改如下:
<string name="template_user_agent" formatted="false">"%1$s/%2$s (Linux; Android)"</string>
相关文章推荐
- string 报错——Android 2.3SDK中关于xml的format问题
- android jni 出现format not a string literal and no format arguments [-Werror=format-security]问题
- JAVA字符串格式化-String.format()的使用 及 Android 中 string.xml 中 字符串格式转化
- <Opencv for Android 调试>加载XML模型,使用SVM.predict出现的NullPointerException问题
- 解决main.out.xml文件出现问题---android开发
- C#使用String.Format()方法时,出现异常"输入的字符串格式有误"的解决方法
- Multiple annotations found at this line: ---关于android string.xml %问题。
- 在使用google map 时出现Android关于java.lang.NoClassDefFoundError问题
- Android,string.xml中使用占位符
- android string.xml %问题。
- android string.xml %问题。
- Android中string.xml使用总结
- 使用android兼容包android-support-v4.jar出现的一些问题
- Android的string.xml中使用html与变量
- Android开发中使用adb shell命令出现sqlite3 : not found 问题
- 在android中使用proguard混淆代码出现“Conversion to Dalvik format failed with error 1”错误的解决方法
- 在android中使用proguard混淆代码出现“Conversion to Dalvik format failed with error 1”错误的解决方法
- android中使用代码混淆出现Conversion to Dalvik format failed with error 1错误的解决办法
- 使用android兼容包android-support-v4.jar出现的一些问题
- Android开发中使用sqlite3出现sqlite3 : not found 问题