This article comes from:Hunter's blog (http://my.oschina.net/hunterXue/blog/15107
)
Multiple annotations found at this line:
-Error: Multiple substitutions specified in non-positional format; did you mean to add the formatted = "false"
Attribute?
-Error: unexpected end tag string
After repeated check, the compilation failed due to % in string. xml,
This is because the new SDK uses the new version of aapt (Android project compiler). This version of aapt compilation will be stricter than the old version, in the string section of the latest Android development documentation, we have explained how to set symbols such as % S. The following is a snippet of the documentation:
If
You need to format your strings using string. Format (string, object ...),
Then you can do so by putting your format arguments in the string
Resource. For example, with the following resource:
If you need to format your string using string. Format (string, object...), you can put the format parameter in your string. See the following example:
<String name = "welcome_messages"> hello, % 1 $ s! You have % 2 $ d new messages. </string>
In
This example, the format string has two arguments: % 1 $ S is a string and
% 2 $ D is a decimal number. You can format the string with arguements
From your application like this:
In this example, the formatted string has two parameters, % 1 $ S is a string % 2 $ D is a floating point number, you canProgramFormat the string according to the parameters in the following method:
Resources res = getresources ();
String text = string. Format (res. getstring (R. String. welcome_messages), username, mailcount );
As mentioned in the example, I need to replace % s with % 1 $ S. After the modification, the program is compiled and started successfully.
Question added:
Some readers ask how to use the "%" in <string> </string>.
There are two ways to choose from
1.
% Is used to indicate 1%, which is the same as the conversion symbol/. 2. If your string does not need to be formatted
Add an attribute on the tag: formatted = "false" for example, <string
Name = "test" formatted = "false"> % test % </string>