How to calculate difference between two date from DatePicker widget

女生的网名这么多〃 提交于 2021-01-29 10:33:49

问题


I've a problem with my GWT project: i'm only interested to calculate the difference between two date (in days) from two DatePicker Widget.

This is my code, i take it mainly from here: http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/datepicker/client/DatePicker.html

    // Create a date picker "FROM: "
    final DatePicker datePicker1 = new DatePicker();
    datePicker1.addValueChangeHandler(new ValueChangeHandler<Date>() {
      public void onValueChange(ValueChangeEvent<Date> event) {
      Date date1 = datePicker1.getValue();
      }
    });
    // Set the default value
    datePicker1.setValue(new Date(), true);

    // Create a date picker "TO: "
    final DatePicker datePicker2 = new DatePicker();
    datePicker2.addValueChangeHandler(new ValueChangeHandler<Date>() {
       public void onValueChange(ValueChangeEvent<Date> event) {
       Date date2 = datePicker2.getValue();        
      }
    });
    // Set the default value
    datePicker2.setValue(new Date(), true);

    // =================DEBUG===================
    Button send = new Button("send", new ClickHandler(){
        public void onClick(ClickEvent event) {
            //calculate difference between date1 and date2
            days = (int) CalendarUtil.getDaysBetween(date1, date2);
            Window.alert("Differece: " + days);
        }
    });

but while i have no error in eclipse, when i run the web application i have this error:

[ERROR] [progetto] Uncaught exception escaped
com.google.gwt.event.shared.UmbrellaException: Exception caught: null
[...]

I can write more error details if necessary but it's very long...

Can you tell me how to fix this error or how to calculate it with an alternative methods?

Thank you in advance.


回答1:


it seems to me one of your object is null. look into exception under this exception, there would be more detail. Second tell me where are you calculating days in code and how? if you share more code it would be helpful. But I think you look for date1 and date2 for null. If you can please share more code, i will be more helpful and do the debugging keeping this in mind.



来源:https://stackoverflow.com/questions/17496056/how-to-calculate-difference-between-two-date-from-datepicker-widget

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