I have an App that store some objects that contain a String date on a file, this String for some operations need to be parsed as GregorianCalendar. Now I have found this issue: when the user change the device language after the creation of the file the App become unable to process the stored file correctly and crashes returning this error
java.text.ParseException: Unparseable date: "27 Sep 2014 23:09:07" (at offset 3)
10-11 14:20:09.573 3745-3745/uk.myapp W/System.err﹕ at java.text.DateFormat.parse(DateFormat.java:561)
the method that returns this error is this
public static GregorianCalendar stringInCalendar(String s, String formatPattern) {
DateFormat format = new SimpleDateFormat(formatPattern);
Date date = null;
try {
date = format.parse(s);
} catch (ParseException e) {
e.printStackTrace();
}
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
return cal;
}
And the error happens on this line date = format.parse(s);
How could I fix this problem?
Note that this error happens only when the device language is changed regardless the type of date. If the device language remains the same, the method doesn't cause any crash
0 comments:
Post a Comment