Apostrophe not preceded by \
AndroidXml ParsingAndroid Problem Overview
I have a string defined in an android application:
<string name="search_occurs">'{string}' occurs {times}</string>
This gives the error: Apostrophe not preceded by \ (in '{string}' occurs {times})
I've tried a number of things to fix this:
<string name="search_occurs">\'{string}\' occurs {times}</string>
<string name="search_occurs">'{string}' occurs {times}</string>
<string name="search_occurs"><![CDATA['{string}' occurs {times}]]></string>
<string name="search_occurs"><![CDATA[\'{string}\' occurs {times}]]></string>
I'm not able to get rid of the error. What am I missing?
Android Solutions
Solution 1 - Android
these should both work according to http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling:
<string name="search_occurs">\'{string}\' occurs {times}</string>
<string name="search_occurs">"'{string}' occurs {times}"</string>
Solution 2 - Android
just put \ before ' in your string It's FALSE It's TRUE :)
Solution 3 - Android
Why don't you provide the '
with the string you replace it with?
Also you know constructs like this?
<string name="profile_age_range_text_between">between %1$d and %2$d</string>
<string name="unit_height_inches">%1$d\'%2$d ft</string>
<string name="unit_distance_miles">%s mi</string>
Solution 4 - Android
Replace Your apostrophe (') with (') or add \ before every (')
note: copy only inside () text
Solution 5 - Android
Make sure that you are editing the correct file. As this answer states, when you get the error, Android Studio opens a values.xml
file, which looks similar to your original file. You have to add the \
in the original strings.xml
file (or wherever the offending character is). Otherwise it will just keep repeating the error.
Solution 6 - Android
In answer to https://stackoverflow.com/users/3339394/the-martian There is general solution for replacing ' by ' you have to copy the text into a word editor(like Notepad ++) and then by using the "replace" option in the program replace whole 's with ' . (cause I've not enough reputation i had to write it in an answer sorry!)
Solution 7 - Android
This Error Is Caused By An Apostrophe Used In String
Replace Apostrophe With ' Thats All
Solution 8 - Android
I got the solution based on my scenario.
- select your string.xml file
- Right click and open show in explorer
- Edit the line from the string.xml file and save the code.
- Reopen Android studio and refresh the solution.
Now the code will run.
Note: I got the error in using Apostrophe on can't. so i change into Cannot. Now my scenario will works.