歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android開發: strings.xml文件中的錯誤

Android開發: strings.xml文件中的錯誤

日期:2017/3/1 10:08:50   编辑:Linux編程

編輯strings.xml的時候
在行<string name="myurl">http://code.dd.com/rr?q=%rr.55</string>
提示下面的錯誤
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

出現這個錯誤的原因主要是因為strings字串中包含百分號(%),

有幾種方式解決
1.用兩個百分號表示一個百分號即
<string name="myurl">http://code.dd.com/rr?q=%%rr.55</string>
2.用轉義符表示
<string name="myurl">http://code.dd.com/rr?q=\%rr.55</string>
3.根據錯誤提示可知,如果字符串無需格式化,可在<string 標簽上增加屬性:formatted="false",即

<string name="myurl" formatted="false">http://code.dd.com/rr?q=%rr.55</string>

Copyright © Linux教程網 All Rights Reserved