反复检查后发现是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> 即可

android string.xml %问题的更多相关文章

  1. Android string.xml error: Apostrophe not preceded by \

    Android string.xml error: Apostrophe not preceded by \ 遇到了这个错误,编译无法通过 error: Apostrophe not preceded ...

  2. 【Android】android string.xml前后加空格的技巧

    android string.xml 文字中间加入空格 <string name="password">密    码</string> &#160 ...

  3. android string.xml里的空格字符

    在string.xml定义字符串的时候常常要用到空格, 直接用键盘敲的话不知道是几个空格,常常看错了,导致误删. 假设用 来替代空格的话,就好非常多. 另外使用%1$s,%1$d能够在一个字符串里定义 ...

  4. Android string.xml 添加特殊字符

    解决项目中在string.xml 中显示特殊符号的问题,如@号冒号等.只能考虑使用ASCII码进行显示: @号 @ :号 : 空格   以下为常见的ASCII十进制交换编码: --> <- ...

  5. Android string.xml 显示特殊符号

    项目中要在string.xml 中显示特殊符号,如@号冒号等,直接写肯定不行啦..只能考虑使用ASCII码进行显示: 省略号 …@号 @:号 :空格   以下为常见的ASCII十进制交换编码: --& ...

  6. android string.xml前后加空格的技巧

    方法1: <string name="password">密    码</string>&#160 这个就代表着空格. 方法2:用\u0020代表空 ...

  7. Android String.xml中的符号总结

    <b></b>加粗字体 <i></i> 斜体字体 <u></u> 给字体加下划线 \n 换行 \u0020表示空格 \u2026 ...

  8. android textview改变部分文字的颜色和string.xml中文字的替换(转)

    转   :http://blog.csdn.net/ljz2009y/article/details/23878669 一:TextView组件改变部分文字的颜色: TextView textView ...

  9. Android Studio 轻松整理字符串到string.xml中

    昨天了解了Alt+Enter快捷键的大用处,今天又发现了一个快捷的方法,必须记下来.转载请注明出处http://www.cnblogs.com/LT5505/p/5466630.html 1.首先代码 ...

随机推荐

  1. python其中一个子线程,则退出全部线程,再退出进程

    import threading, signal is_exit = False def write_login(self): global is_exit write_log('login rsyn ...

  2. 华为OJ平台——DNA序列

    题目描述: 一个DNA序列由A/C/G/T四个字母的排列组合组成.G和C的比例(定义为GC-Ratio)是序列中G和C两个字母的总的出现次数除以总的字母数目(也就是序列长度).在基因工程中,这个比例非 ...

  3. 09_platform-tools简介&常见adb指令

    SDK下面的文件夹说明add-ons 附加的附属的一些信息.docs Android开发的帮助文件.extras 支持的jar包,高版本兼容底版本.google usb的驱动.platforms 存放 ...

  4. 如何用ASPxTreeView建立三级树(显示及数据绑定)

    示例如图: //设置treeviw默认为第一个菜单打开if (ASPxTreeView1.SelectedNode == null)ASPxTreeView1.SelectedNode = ASPxT ...

  5. Android SharedPreferences 见解

    今天突然遇到了SharedPreferences问题,虽然以前用过,但从没有深入的了解一下,今天就顺便深入了解一下,并总结一下,防止以后忘记. SharePreferences是Android平台上一 ...

  6. C# 中DataGridView 绑定List<T>做数据源的操作问题

    若想将 List<T>作为DataGridView的数据源,然后后续还想继续操作的话,需要将List<T>赋值给BindingList对象, 然后直接将BindingList赋 ...

  7. 571亿背后:DRC助阿里实现异地双活

    571亿背后:DRC助阿里实现异地双活 赶集网SQL自动上线

  8. Objective-C的基础语法总结

    1.NSLog(@“hello world!”);//打印语句的函数,需要打印的字符串放在@之后. NSLog(@“are %d and %d different?%@”,4,4,@”YES”); 2 ...

  9. box2d 遍历世界中 body 的方法

    大家都知道,循环遍历有很多方法,在box2d中大家普遍使用while和for循环来遍历世界,那什么时候使用for,什么时候使用while呢? 当循环中不设计body删除的时候,使用for循环,即: C ...

  10. Linux程序分析工具:ldd和nm

    ldd和nm是Linux下两个非常实用的程序分析工具.其中,ldd是用来分析程序运行时需要依赖的动态链接库的工具,nm是用来查看指定程序中的符号表信息的工具. 1 ldd 格式:ldd [option ...