Multiple annotations found at this line:-about Android string. xml %

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.