• Android在Eclipse下编译String.xml出现Multiple substitutions specified in nonpositional format 错误


    【问题描述】

    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中的 % 导致编译失败。

    【解决办法】

    1.用%%来表示1个%,和转意符号 \ 的用法相同
     
    2.如果你的字符串不需要格式化,可以在你的<string 标签上增加一个属性:formatted="false"例如 <string name="test" formatted="false">% test %</string> 即可
     
    【问题补充】
    新的SDK编译更加严格,对特殊字符要特别处理:

    1、遇到如下错误的时候说明你需要在单引号签名加转义字符(\):

    Description Resource Path Location Type error: Apostrophe not preceded by \ (in Search' Titles) strings.xml

        只要将定义的字符串中的单引号('), 修改为(\')即可

     

    2、变量文本格式(%s)提示:

     在Android最新的开发文档中描述String的部分,已经说明了如何去设置 %s 等符号.
    简单解决方法就是:把%s之类的变量格式替换成%1$s, %1表示第一个位置的变量, $s表示为字符串类型
    例如:

    <string name="welcome_messages">Your First Var is %1$s! You Second Var is %2$d.</string>
     
    3、之前有个项目中需要用到角度符号° 然后我非常自然地把这个符号复制粘帖到xml里了, 试了下还不错. 后来发现其他一些设备却会显示错误. 汗... 然后...然后就找到这些:

    在xml中可以用unicode来表示一些特殊字符, 比如"..."可以用/u2026来表示, 而"°"可以用/u00B0来表示.

    4、附xml中常用的转义字符:

    <              &lt;

    >              &gt;

    &              &amp;

    ' (单引号)   &apos;

    "(双引号)   &quot;

     

  • 相关阅读:
    设计模式(6)--Adapter(适配器模式)--结构型
    设计模式原则(1)--Single Responsibility Principle(SRP)--单一职责原则
    设计模式(5)--Builder(建造模式)--创建型
    设计模式(4)--AbstractFactory(抽象工厂模式)--创建型
    设计模式(3)--SimpleFactory( [1] 简单工厂模式)--创建型
    JS 的map和array集合组合返回JSON字符串
    HTML中直接写js 函数
    设计模式(3)--FactoryMethod( [2] 工厂方法模式)--创建型
    图片剪贴工具类
    远程Get,Post请求工具类
  • 原文地址:https://www.cnblogs.com/qsl568/p/2334415.html
Copyright © 2020-2023  润新知