Android ADT 21.0 warning: Implicitly using the default locale

后端 未结 6 1400
感情败类
感情败类 2020-12-29 19:38

I\'ve updated ADT to v. 21 and new warning appeared in this code:

if (e.getMessage().toLowerCase().contains(\"blabla\"))

Implicitly using the default locale         


        
相关标签:
6条回答
  • 2020-12-29 19:51

    Actually, use Locale.getDefault() when the goal is to present text to the user. However, and this is the whole point of the Lint check, you should probably be using Locale.US whenever the goal is for machine readability/usage. Because it is already implicitly using Locale.getDefault() if you don't specify one, and this can cause hard to find bugs when devices have their own default locale specified. It seems that you also need to clean your project either way, as everyone else has suggested.

    0 讨论(0)
  • 2020-12-29 19:59

    It's probably a Lint bug. Just try to cut the whole line of code

    if (e.getMessage().toLowerCase(Locale.ENGLISH).contains("blabla"))
    

    save, then paste.

    0 讨论(0)
  • 2020-12-29 20:02

    You should use Locale.getDefault() especially if you cant be sure that your text will always be in english. Also lint errors like that one you are having usually disappear after you run lint again or clean your project.

    0 讨论(0)
  • 2020-12-29 20:03

    Cleaning the project didn't work for me, so I added the default locale on my code:

    String.format(Locale.getDefault(), "firstname: %s, lastname: %s", firstName, lastName));

    Depending on your project, you might want to take a look at the Locale explanation.

    0 讨论(0)
  • 2020-12-29 20:04

    use Locale.getDefault() and than clean your project.

    0 讨论(0)
  • 2020-12-29 20:08

    You simply need to clean your project by clicking:

    Build > Clean Project or Build > Rebuild Project

    0 讨论(0)
提交回复
热议问题