1

I've created a datepicker. I need to restrict the future date selection. So i use datePicker.setMaxDate(new Date().getTime()); . Without this date picker works fine. After this i am changing date randomly in past. I got this crash message in Logcat.

 02-03 13:44:56.858: E/AndroidRuntime(7435): FATAL EXCEPTION: main
 java.lang.IllegalArgumentException: Time not between Mon Jan 01 00:00:00 GMT 1900 and Mon Feb 03 13:43:48 GMT 2014
    at android.widget.CalendarView.goTo(CalendarView.java:1128)
    at android.widget.CalendarView.setDate(CalendarView.java:960)
    at android.widget.DatePicker.updateCalendarView(DatePicker.java:880)
    at android.widget.DatePicker.access$800(DatePicker.java:99)
    at android.widget.DatePicker$1.onValueChange(DatePicker.java:256)
    at android.widget.NumberPicker.notifyChange(NumberPicker.java:1862)
    at android.widget.NumberPicker.setValueInternal(NumberPicker.java:1647)
    at android.widget.NumberPicker.changeValueByOne(NumberPicker.java:1675)
    at android.widget.NumberPicker.access$200(NumberPicker.java:100)
    at android.widget.NumberPicker$1.onClick(NumberPicker.java:651)
    at android.view.View.performClick(View.java:4421)
    at android.view.View$PerformClick.run(View.java:18190)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:175)
    at android.app.ActivityThread.main(ActivityThread.java:5279)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)

There is nothing mention about my java error. Anyone have idea about this please help.

Amsheer
  • 7,046
  • 8
  • 47
  • 81
  • java.lang.IllegalArgumentException: Time not between Mon Jan 01 00:00:00 GMT 1900 and Mon Feb 03 13:43:48 GMT 2014 Did you notice this error?? which date you have given?? is it in gmt?? – Jithu Feb 03 '14 at 13:58
  • What is that mean i don't understand. Please explain. – Amsheer Feb 03 '14 at 13:59
  • have you tried like this setMaxDate(System.currentTimeMillis()); – Maulik.J Feb 03 '14 at 14:00
  • Now i tried System.currentTimeMillis() too but not helps. Datepicker works fine only disable datePicker.setMaxDate(new Date().getTime()); – Amsheer Feb 03 '14 at 14:03
  • try this it will help http://stackoverflow.com/questions/15686865/datepicker-setmindatelong-mindate-throws-illegalargumentexception-time-not-be – Maulik.J Feb 03 '14 at 14:04
  • Have any idea what is the problem with datePicker.setMaxDate(new Date().getTime()); – Amsheer Feb 03 '14 at 14:09

2 Answers2

1

It is happen because i'm try to set datePicker.setMaxDate(new Date().getTime()); inside of my show dialog method i called it many time that is the reason it crashes. Call datePicker.setMaxDate(new Date().getTime()); only once it'll fine now

Amsheer
  • 7,046
  • 8
  • 47
  • 81
0

Try using

datePicker.setMaxDate(Calendar.getInstance().getTimeInMillis());

instead of

datePicker.setMaxDate(new Date().getTime());

This will set today's date as max date and no future date will be allowed to be selected.

Apoorv
  • 13,470
  • 4
  • 27
  • 33