Error in string. XML in Android-multiple annotations found at this line

Source: Internet
Author: User

This article comes from:Hunter 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, in your program, you can format the string according to the following parameters:

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. use % to indicate 1%, which is the same as the usage of the conversion symbol. if your string does not need to be formatted, you can add an attribute on your <string Tag: formatted = "false" for example, <string name = "test" formatted = "false"> % test % </string>.

Related Article

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.