Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have android app and this string in resources:

<string name="create_group_select_people">Select up to %1$d people!</string> 

This is called from fragment:

Integer countMax = 5; //also tried just "int" - nothing changed getResources().getString(R.string.create_group_select_people, countMax); 

but I got error:

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

I can't understand what is wrong? When I launch app - it shows me literally "Select up to %1$d people!"

like image 916
Wackaloon Avatar asked Nov 23 '16 13:11

Wackaloon


People also ask

Which of the format string is not valid?

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

What is string format () in Java?

In java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string.

How do you change a string format?

String startTime = "08/11/2008 00:00"; // This could be MM/dd/yyyy, you original value is ambiguous SimpleDateFormat input = new SimpleDateFormat("dd/MM/yyyy HH:mm"); Date dateValue = input. parse(startTime);


2 Answers

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
like image 97
ohdroid Avatar answered Oct 01 '22 15:10

ohdroid


Set parameter formatted to true in resources:

<string name="some_text" formatted="true">     Use for String.format method. Parameter one: %s1 </string> 

and use this way:

String.format(context.getString(R.string.some_text,"value 1")) 

or this way:

context.getString(R.string.some_text,"value 1")) 

Note:formatted flag should be set to true only for strings with placeholders

like image 23
MiguelSlv Avatar answered Oct 01 '22 13:10

MiguelSlv