Multiple annotations found at this line:---about the android string.xml% problem.

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 checking, it was found that% of String.xml caused the compilation to fail.

This is because the new SDK uses a new version of AAPT (the Android Project compiler), and this version of the AAPT is more rigorous than the older version, and then, in the section on Android's latest development documentation, describes how to set symbols such as%s. The following is a document fragment:

If you are need to format your strings using String.Format (String, Object ...), then you can did by putting your format Argu ments in the string resource. For example, with the following resource:

If you need to use String.Format (String, Object ...) to format your string, you can put the formatting parameters 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 case, the formatted string has 2 parameters, and%1 $ s is a string%2$d is a floating-point number, and you can format the string according to the parameters in your program by using the following method:

Resources res = getresources ();

String Text = String.Format (res.getstring (r.string.welcome_messages), username, mailcount);

So according to the example, I need to change the%s to%1 $ s, and then compile it, and the program starts successfully.

Question added:

A reader asks how to use the% number in <string></string>

There are two ways to choose
1.1% per percent, as in the use of the symbol/2. If your string does not need to be formatted, add an attribute to your <string tag: formatted= "false" such as <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.