Android SDK: UnknownFormatConversionException

I’ve been working on a weird exception for the past couple hours and finally figured it out. Since I couldn’t find any information about this exception I figured I’d post about it.  

It happens in my SettingsActivity, which extends SherlockPreferenceActivity. The cause is my string-array of values that have a percent sign in them, and when I set the preference summary that has a percent sign, the OS tries to format that percent sign. There are a few ways to escape the percent signs, but none of them worked. If I used 2 %% signs, it set the summary without an exception, but it showed up as “%%” in the select list. None of the HTML encodings worked either. I even tried to HTML encode the whole string when I set the summary, but I don’t think there is a way to escape the % sign unless you escape it with another %, and that just shows up as “%%” which is unacceptable in my application. So, for now, it will just be “percent”. Lame.

Stack Trace:

java.util.UnknownFormatConversionException: Conversion: 
 at java.util.Formatter$FormatSpecifierParser.unknownFormatConversionException(
 at java.util.Formatter$FormatSpecifierParser.advance(
 at java.util.Formatter$FormatSpecifierParser.parseConversionType(
 at java.util.Formatter$FormatSpecifierParser.parseArgumentIndexAndFlags(
 at java.util.Formatter$FormatSpecifierParser.parseFormatToken(
 at java.util.Formatter.doFormat(
 at java.util.Formatter.format(
 at java.util.Formatter.format(
 at java.lang.String.format(
 at java.lang.String.format(
 at android.preference.ListPreference.getSummary(


Barry Bostwick

Thanks for the post! I had this same problem. My best substitution was replacing the % symbols with ‰, the per mille sign (ascii code: 137). The symbol itself has a different meaning, but at least it looks similar to % and Java won't try and go formatting all willy nilly lol.

Leave a comment

Your email address will not be published. Required fields are marked *