日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Multiple annotations found at this line: ---关于android string.xml %问题

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Multiple annotations found at this line: ---关于android string.xml %问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文來源于:hunter的博客(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

?反復檢查后發現是string.xml中的?%?導致編譯失敗,

這是由于新的SDK采用了新版本的aapt(Android項目編譯器),這個版本的aapt編譯起來會比老版本更加的嚴格,然后在Android最新的開發文檔的描述String的部分,已經說明了如何去設置 %s 等符號,下面是文檔片段:

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:

如果你需要使用 String.format(String, Object...) 來格式化你的字符串,你可以把格式化參數放在你的字符串中,參見下面的例子:

<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:

在這個例子中,這個格式化的字符串有2個參數, %1$s是個字符串 %2$d 是個浮點數,你可以在你的程序中按照下面的方法來根據參數來格式化字符串:

Resources res = getResources();

String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);

那么根據例子上說的我需要把%s換成%1$s才行了,修改后編譯通過,程序成功啟動。

問題補充:

有讀者問如何在<string></string>中使用%號

有兩個辦法可供選擇
1.用%%來表示1個%,和轉意符號 / 的用法相同?2.如果你的字符串不需要格式化,可以在你的<string 標簽上增加一個屬性:formatted="false"例如 <string name="test"?formatted="false">% test %</string> 即可

轉載于:https://www.cnblogs.com/firstWolf/archive/2012/04/06/string.html

總結

以上是生活随笔為你收集整理的Multiple annotations found at this line: ---关于android string.xml %问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。