Format string XXX is not a valid format string so it should not be passed to String.format

前端 未结 12 2169
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 23:06

I have android app and this string in resources:

Select up to %1$d people!

Thi

相关标签:
12条回答
  • 2021-02-06 23:43

    Try File -> Invalidate Caches / Restart..., it fixed the problem for me.

    0 讨论(0)
  • 2021-02-06 23:43

    In my case invalidating cache with restart did not help, but having consistent formatting parameters (e.g. %s) across other the locales resolved the issue. I hope this might be helpful to someone in the future.

    0 讨论(0)
  • 2021-02-06 23:44

    For the formatting of the string to be correct:

    String.format(Locale.ENGLISH, itemView.context.getString(R.string.XXX), "%17") 
    

    Also the special characters do not have to interfere with the injection of parameters. For that, take into account the exhaust outlets for special characters

    From: <string name="XXX">% %1$s</string>

    To: <string name="XXX">%1$s</string>

    Finally XXX is "%17"

    Good Luck.

    Source

    0 讨论(0)
  • 2021-02-06 23:46

    You're probably missing the format method of the String class, If you're setting it in a TextView, the proper way is:

    textView.setText(String.format(getResources().getString(R.string.create_group_select_people), countMax));
    
    0 讨论(0)
  • 2021-02-06 23:47

    Try doing a 'clean project' followed by a close and reopen of Android Studio.

    That fixed it for me, it looks like some minor Android Studio /Lint bug.

    0 讨论(0)
  • 2021-02-06 23:51

    I just copied the code and it works well. so you may need to check some other place,Here are my suggestions.

    1. clean project
    2. check multi-language files
    3. or just use String.format just like others said
    0 讨论(0)
提交回复
热议问题