Android string.xml error: Apostrophe not preceded by \

时间:2023-03-08 19:31:27
Android string.xml error: Apostrophe not preceded by \

Android string.xml error: Apostrophe not preceded by \

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

错误的代码是:

   <string name="security_protocol_dialog_content_1_msg">Restoring factory settings, the system will erase the phone's data without warning.</string>

正确的代码是:

   <string name="security_protocol_dialog_content_1_msg">Restoring factory settings, the system will erase the phone\'s data without warning.</string>

额外加了一个转义字符(\)

当字符串中包含单引号(')的时候,就需要转义字符进行转义。

XML中的特殊字符:

单引号   '      '
双引号 " "
大于号 > >
小于号 < <
与 & &