Reputation: 341
Hi hopefully this fulfils the criteria for being a well written question. I'm new to programming and I've been trying to write an application for climbers on android that tells the user what they should be climbing based on their current ability for a training period. The app requires the user to input their climbing ability and the length of their wall.
I've set up a preferences menu using SharedPrefences
for this with a numeric edit text field and a list.
Initially I had an class cast exception as I was trying to use the string from the edit text as a float/double/int (I tried all three!).
I've converted the string to a double using Double = Double.valueof(StringFromPrefernce)
which solved that error but is now producing the error java.util.FormatFlagsConversionMismatchException: %o does not support ' '
which I've not been able to find a solution for.
The app allows the user to access the preference menu initially, however once they have set some values any attempt to access the preference menu will produce this force close.
SOLUTION:
In my preferences.xml I had referenced a string. That string contained a % symbol which was responsible for the force close. Removing the % symbol fixed the issue.
Upvotes: 10
Views: 17699
Reputation: 1289
you need to add formatted="false"
attribute in your string
See Android XML Percent Symbol
Upvotes: 1
Reputation: 5381
As per RominaLiuzzi's comment. You don't need to delete the %. You can escape it with %%
Upvotes: 0
Reputation: 62549
i was getting that because i was using a tool to do automatic translations. it was putting in % s
instead of %s
.
Upvotes: 7
Reputation: 221
Appears to be a change in Android 4. Doubling the % symbol in your string appears to work - % now appears to be an escape character so self-escaping with %% did it for me.
Upvotes: 22
Reputation: 341
SOLUTION:
In my preferences.xml I had referenced a string. That string contained a % symbol which was responsible for the force close. Removing the % symbol fixed the issue.
Upvotes: 9
Reputation: 20944
Try to trim the input string:
Double d = Double.valueof(StringFromPrefernce.trim());
This should remove unnecessary whitespaces from the beginning and the end of your string. Also it is better to surround your call with try/catch to avoid invalid input:
Double d = 0;
try
{
d = Double.valueof(StringFromPrefernce.trim());
}
catch(NumberFormatException e)
{
e.printStackTrace();
}
Upvotes: 0