%s%% not valid string format, why?

2,443 views
Skip to first unread message

Mark Carter

unread,
Nov 15, 2012, 12:43:19 AM11/15/12
to adt...@googlegroups.com
I'm getting a lint error for this:

<string name="downloading_audio">正在下载音频 (已完成 %s%%)…</string>

I want to show something like:

正在下载音频 (已完成 42%)…

Dallas Gutauckis

unread,
Nov 15, 2012, 12:46:19 AM11/15/12
to adt...@googlegroups.com

Mark Carter

unread,
Nov 15, 2012, 1:32:35 AM11/15/12
to adt...@googlegroups.com
Thanks - I tried the various answers but none of them made a difference unfortunately.

It looks like the Lint checker is confused into thinking %s%% is two parameters and then goes on to fail because the second parameter is not of the correct format.

Note - the format works perfectly well in String.format

Am I missing something?

Tor Norbye

unread,
Nov 15, 2012, 1:34:31 AM11/15/12
to adt...@googlegroups.com
Try switching to positional format;  %1$s%%

Mark Carter

unread,
Nov 15, 2012, 1:40:54 AM11/15/12
to adt...@googlegroups.com
Yep, I tried that (and also with and without the backslash suggestion) but still no luck...

Mark Carter

unread,
Nov 15, 2012, 1:47:02 AM11/15/12
to adt...@googlegroups.com
Something strange happening - if I remove the localized versions so that downloading_audio is only defined in values/strings.xml then I get a different error:

"Wrong argument count, format string downloading_audio requires 2 but format call supplies 1"

This happens irrespective if I use positional format or not.

Tor Norbye

unread,
Nov 15, 2012, 1:50:22 AM11/15/12
to adt...@googlegroups.com
Sounds like a weird bug. Would you mind sending the exact <string> item to reproduce the error (or a simplified version which still triggers both types of errors?).

-- Tor

Mark Carter

unread,
Nov 15, 2012, 1:53:57 AM11/15/12
to adt...@googlegroups.com
<string name="test">%s%%</string>

<string name="test">%1$s%%</string>

Mark Carter

unread,
Nov 15, 2012, 2:07:35 AM11/15/12
to adt...@googlegroups.com
To get the wrong argument count error:

<string name="test">%s%% c</string>

and have this code:

getString(R.string.test, "hello");

Same result for any string starting with those chars, e.g. <string name="test">%s%% cjkfhsdjfsdjkfh</string>

However, this:

<string name="test">%s%% </string> gives the same error I first reported:

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

Tor Norbye

unread,
Nov 20, 2012, 6:06:04 PM11/20/12
to adt...@googlegroups.com
Just to close out this thread; this is also tracked in issue

-- Tor

Dallin Wilcox

unread,
Feb 7, 2014, 10:54:12 AM2/7/14
to adt...@googlegroups.com
Looks like this issue is also affecting the other zero-argument conversion string, %n.  I submitted a bug for it:https://code.google.com/p/android/issues/detail?id=65692.

-Dallin

Tor Norbye

unread,
Feb 7, 2014, 7:07:01 PM2/7/14
to adt...@googlegroups.com
Thanks! Should be fixed for next version of the Gradle plugin and Studio.

-- Tor


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages