在Android 5.0 Jodatime问题 [英] Jodatime issues on Android 5.0

查看:277
本文介绍了在Android 5.0 Jodatime问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序已经工作了一段时间,而Android 5.0发布后它崩溃上运行此版本的设备。
我使用JodaTime 2.6日期处理,它的这个库突然抛出以下异常:

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异常:无效的格式为:上午6时06分00秒的AM

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(这里是code失败)

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?

推荐答案

这是一个可能的定位问题即可。看来,你的默认本地不知道AM-string,但别的东西。

This is probably a localization issue. It appears that your default local does not know the "AM"-string, but something else.

乔达时仅委派给底层的JVM的资源,你的情况到Android资源可以是不同的。要做到这一点,乔达时最后用类的DateFormatSymbols 。请检查您的语言环境和 getAmPmStrings的输出()对于正确的诊断。

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.

在诊断结果依赖通过使用显式设置区域 LocalTime.parse(timeToParse,fmt.withLocale(区域设置区域设置)); 帮助,或者您使用一个合适的形式字符串输入preprocessing的。

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.

这篇关于在Android 5.0 Jodatime问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆