Android force close with JodaTime

余生颓废 提交于 2019-12-07 19:36:20

问题


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  

回答1:


This occurs because user.timezone system property is null. See http://sourceforge.net/tracker/?func=detail&aid=3056104&group_id=97367&atid=617889



来源:https://stackoverflow.com/questions/3431105/android-force-close-with-jodatime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!