0

I've read others posts about this link warning but they didn't solve my problem and I still don't get what I've doing wrong.

In default file strings.xml, I have:

 <string name="rating_dialog">You\'re about to rate this app with %s stars.</string>

Later, I call it inside an override onClick method:

 v.getContext().getString(R.string.rating_dialog, String.valueOf(rating))

It's appearing like:

You're about to rate this app with {String.valueOf(rating)} stars.

Link Warning:

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

Note:

v is a View and rating is an int value.

I've checked other strings.xml files for other languages, and all translations seems alright.

Solved: for hindi string.xml, instead of %s, there was only %.

2 Answers2

0

You need to assign a position to each placeholder you define in your XML.

Your string then becomes:

<string name="rating_dialog">You\'re about to rate this app with %1$s stars.</string>
StuStirling
  • 15,601
  • 23
  • 93
  • 150
0

You can do it like below:

In string.xml:

If you want to assign integer value then use "%1$d" and if String then use "%1$s"

1 is use for defining position. If you want to use multiple values then you can use "%1$d","%2$d",....etc

<string name="rating_dialog">You\'re about to rate this app with %1$d stars.</string>

Then in code do it like :

v.getContext().getString(R.string.rating_dialog, rating);

Hope it helps you.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47