Android的力量亲近JodaTime [英] Android force close with JodaTime
问题描述
有没有人使用jodatime与Android?我越来越紧密,不留痕迹的力量。
包test.journal.help;进口java.util.Date;进口org.joda.time.DateTime;
进口org.joda.time.Days;进口android.app.Activity;
进口android.os.Bundle;
公共类journaltester延伸活动{
/ **当第一次创建活动调用。 * / 私人今天的日期=新的日期(); 公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
天天= Days.daysBetween(新日期时间(今天),新日期时间(今天));
的setContentView(R.layout.main); }
}
今天的价值:星期六8月7日0点00分○○秒美国/纽约2010
好吧取得一些进展...
获得根据kiwidoc在org.joda.time.DateTimeZone.getDefault()一个计算器这个错误造成,如果区域为null。
公共静态DateTimeZone getDefault(){
DateTimeZone区= cDefault;
如果(区== NULL){
同步(DateTimeZone.class){
区段= cDefault;
如果(区== NULL){
DateTimeZone温度= NULL;
尝试{
尝试{
TEMP = FORID(System.getProperty(user.timezone));
}赶上(RuntimeException的前){
//忽略
}
如果(临时== NULL){
TEMP = forTimeZone(TimeZone.getDefault());
}
}赶上(抛出:IllegalArgumentException前){
//忽略
}
如果(临时== NULL){
TEMP = UTC;
}
cDefault =区段=温度;
}
} // LINE 147
}
返回区;
}
继承人的堆栈:
发[3;>主](吊(例外的StackOverflowError))
DateTimeZone.getDefault()行:147
ISOChronology.getInstance()行:86
DateTimeUtils.getChronology(年表)线:231
DateConverter(AbstractConverter).getChronology(对象,年表)行:82
。日期时间(BaseDateTime)LT; INIT>(对象,年表)线:170
。日期时间<&初始化GT;(对象)线:168
PlantsCursorAdapter.newView(背景下,光标的ViewGroup)行:71
PlantsCursorAdapter(CursorAdapter的).getView(INT,查看,ViewGroup中)线:182
这是因为 user.timezone
系统属性为null。见<一href=\"http://sourceforge.net/tracker/?func=detail&aid=3056104&group_id=97367&atid=617889\" rel=\"nofollow\">http://sourceforge.net/tracker/?func=detail&aid=3056104&group_id=97367&atid=617889
Has anybody used jodatime with android? I'm getting a force close with no trace.
package test.journal.help;
import java.util.Date;
import org.joda.time.DateTime;
import org.joda.time.Days;
import android.app.Activity;
import android.os.Bundle;
public class journaltester extends Activity {
/** Called when the activity is first created. */
private Date today = new Date();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Days days = Days.daysBetween(new DateTime(today), new DateTime(today));
setContentView(R.layout.main);
}
}
Value of today : "Sat Aug 07 00:00:00 America/New_York 2010"
alright making some progress... getting a stackoverflow error at org.joda.time.DateTimeZone.getDefault() according to kiwidoc this is caused if zone is null.
public static DateTimeZone getDefault() {
DateTimeZone zone = cDefault;
if (zone == null) {
synchronized(DateTimeZone.class) {
zone = cDefault;
if (zone == null) {
DateTimeZone temp = null;
try {
try {
temp = forID(System.getProperty("user.timezone"));
} catch (RuntimeException ex) {
// ignored
}
if (temp == null) {
temp = forTimeZone(TimeZone.getDefault());
}
} catch (IllegalArgumentException ex) {
// ignored
}
if (temp == null) {
temp = UTC;
}
cDefault = zone = temp;
}
} //LINE 147
}
return zone;
}
Heres the stack:
Thread [<3> main] (Suspended (exception StackOverflowError))
DateTimeZone.getDefault() line: 147
ISOChronology.getInstance() line: 86
DateTimeUtils.getChronology(Chronology) line: 231
DateConverter(AbstractConverter).getChronology(Object, Chronology) line: 82
DateTime(BaseDateTime).<init>(Object, Chronology) line: 170
DateTime.<init>(Object) line: 168
PlantsCursorAdapter.newView(Context, Cursor, ViewGroup) line: 71
PlantsCursorAdapter(CursorAdapter).getView(int, View, ViewGroup) line: 182
This occurs because user.timezone
system property is null. See http://sourceforge.net/tracker/?func=detail&aid=3056104&group_id=97367&atid=617889
这篇关于Android的力量亲近JodaTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!