My app has been working for some time, but after the release of Android 5.0 it crashes on devices running this version. I'm using JodaTime 2.6 for date handling and it's this library that suddenly throws the following exception:
java.lang.IllegalArgumentException: Invalid format: "6:06:00 AM" is malformed at "AM"
Ive verified that the corresponding string I'm trying to parse has the correct format.
UPDATE(Here is code that fails)
private void doSomething(DateTime time, String timeToParse,int day, int month) {
DateTimeFormatter fmt = DateTimeFormat.forPattern("h:mm:ss a");
//Fails here:
LocalTime timeFromString = LocalTime.parse(timeToParse,fmt);
}
Anyone experience similar issues?
This is probably a localization issue. It appears that your default local does not know the "AM"-string, but something else.
Joda-Time just delegates to the underlying JVM-resource, in your case to the Android-resources which can be different. To do so, Joda-Time finally uses the class
DateFormatSymbols
. Please check your locale and the output of getAmPmStrings() for a proper diagnosis.Dependent on the result of the diagnosis either setting the locale explicitly by using
LocalTime.parse(timeToParse, fmt.withLocale(Locale locale));
helps, or you use a suitable form of string input preprocessing.