I have an array of strings in which the %
symbol is used. Proper format for using the %
is %
. When I have a string in that array with multiple %
it gives me this error.
Multiple annotations found at this
line:
- error: Multiple substitutions specified in non-positional format;
did you mean to add the formatted="false" attribute?
- error: Found tag </item> where </string-array> is expected
Best Answer
The Android Asset Packaging Tool (
aapt
) has become very strict in its latest release and is now used for all Android versions. The aapt-error you're getting is generated because it no longer allows non-positional format specifiers.Here are a few ideas how you can include the %-symbol in your resource strings.
If you don't need any format specifiers or substitutions in your string you can simply make use of the
formatted
attribute and set it tofalse
:In this case the string is not used as a format string for the
Formatter
so you don't have to escape your %-symbols. The resulting string is "%a + %a == 2%a".If you omit the
formatted="false"
attribute, the string is used as a format string and you have to escape the %-symbols. This is correctly done with double-%:Now
aapt
gives you no errors but depending on how you use it, the resulting string can be "%%a + %%a == 2%%a" if aFormatter
is invoked without any format arguments:Without any xml and code it is difficult to say what exactly your problem is but hopefully this helps you understand the mechanisms a little better.