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
  • 1
    In string resources, you need to use %1$s (and %2$s etc.. for further variables) Commented Feb 2, 2017 at 9:51
  • 1
    It has been answered here: stackoverflow.com/questions/12627457/… Commented Feb 2, 2017 at 9:53

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I applied this (and checked untranslatable so translations can't have a impact) but still the same problem.
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.

3 Comments

Thank you, I applied all your steps, with %1$d and %1$s and checked "untranslatable" in Translations Editor (so translations can't have a impact) but still the same problem.
can you please try like String message = getString(R.string.rating_dialog, rating); ?
The problem was the hindi strings.xml, instead of %s, there was only %. But thank you again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.