当显式使用Locale.US时,为什么Android Lint会使用默认语言环境警告String.format? [英] Why does Android Lint warn about String.format using default locale when explicitly using Locale.US?

查看:227
本文介绍了当显式使用Locale.US时,为什么Android Lint会使用默认语言环境警告String.format?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初这样称呼 String.format :

return String.format("%s %f %f", anotherString, doubleA, doubleB);

哪个使Android Lint生成此警告:

Which made Android Lint generate this warning:

简单地使用默认语言环境是常见的错误来源:改为使用String.format(Locale,...)

Implicitly using the default locale is a common source of bugs: Use String.format(Locale, ...) instead

因此,根据我在 Locale.US .html> http://developer.android.com/reference/java/util/Locale.html 下的警惕默认语言环境"部分:

So I changed it to use Locale.US explicitly, based on what I read at http://developer.android.com/reference/java/util/Locale.html under the "Be wary of the default locale" section:

return String.format(Locale.US, "%s %f %f", anotherString, doubleA, doubleB);

为什么Android Lint仍然会生成相同的警告?我必须在Eclipse中清理项目以摆脱它,因为大多数警告只是在解决了有问题的行后就消失了.我不确定自己是否做错了.

Why does Android Lint still generate the same warning? I have to clean the project in Eclipse to get rid of it, when most warnings just disappear as soon as the offending line is fixed. I'm not sure if I'm doing something wrong or not.

推荐答案

清理和重建项目应该可以.

Cleaning and rebuilding the project should work.

顺便说一句,您可能想使用 Locale.getDefault()来照顾"非英语文字.

BTW, you may want to use Locale.getDefault() to "take care" of texts not written in english.

这篇关于当显式使用Locale.US时,为什么Android Lint会使用默认语言环境警告String.format?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆