lolliloop
lolliloop

Reputation: 399

Error with datepicker in android

I creates a date picker as shown in the picture. It show up when I run the program on tabs but when I tried it phone (HTC Glacier) the application crash, I can figure out where I missed something. Help me please. Thanks enter image description here

here is my logcat:

06-24 16:52:05.003: E/AndroidRuntime(19717): Caused by: java.lang.IllegalArgumentException: current should be >= start and <= end
06-24 16:52:05.003: E/AndroidRuntime(19717):    at android.widget.NumberPicker.setCurrent(NumberPicker.java:288)
06-24 16:52:05.003: E/AndroidRuntime(19717):    at     android.widget.DatePicker.updateSpinners(DatePicker.java:384)
06-24 16:52:05.003: E/AndroidRuntime(19717):    at android.widget.DatePicker.init(DatePicker.java:379)
06-24 16:52:05.003: E/AndroidRuntime(19717):    at ph.com.unilab.iReport.IreportMain.onCreate(IreportMain.java:85)

here is my code in main activity for the datepicker

 ....
calendar = Calendar.getInstance();
dp_Date = (DatePicker) findViewById(R.id.dp_Date);
dp_Date.init(80, calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE), null);

dp_Date.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
dp_Date.init(2013, calendar.getTime().getMonth(), calendar.getTime().getDate(), new OnDateChangedListener()
{
  public void onDateChanged(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
}
    });

....

Upvotes: 0

Views: 428

Answers (2)

Zarokka
Zarokka

Reputation: 3056

Your init code is quite strange and uses deprecated methods. Try this:

calendar = Calendar.getInstance();
datePicker = (DatePicker) findViewById(R.id.dp_Date);    
datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),   calendar.get(Calendar.DAY_OF_MONTH), new OnDateChangedListener() {
      public void onDateChanged(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
      //TODO do stuff on date change
      }
});

Upvotes: 1

Thalaivar
Thalaivar

Reputation: 23622

Have you Initialized the year, monthOfYear and dayOfMonth

private int mYear = 2012;
private int mMonth = 12;
private int mDay =12;

Upvotes: 1

Related Questions