2012-01-13 56 views
0
我有在创建日期选择器,我不知道为什么问题

....这是我使用的代码片段:为什么这个日期选择器不起作用?

private static final int DATE_PICKER_DIALOG = 800; 


@Override 
protected Dialog onCreateDialog(int id) { 
    switch (id) { 
    case DATE_PICKER_DIALOG: 
     final Calendar calendar = Calendar.getInstance(); 
     return new DatePickerDialog(getApplicationContext(), 
       datePickerCallback, calendar.get(Calendar.YEAR), calendar 
         .get(Calendar.MONTH), calendar 
         .get(Calendar.DAY_OF_MONTH)); 
    } 
    return null; 
}; 

对话框被调用:

showDialog(DATE_PICKER_DIALOG) 

这是抛出一个IllegalArgumntException:当前应该是> =开始和....

为什么呢?谢谢!

+0

粘贴logcat并指向给出前的行。 – 2012-01-13 12:59:51

+0

异常是我创建新对话框的地方 – 2012-01-13 13:17:02

回答

1

日历对象的月份从0开始计数。您试图将DatePicker中的月份设置为0(1月份),但它只能设置为1-12。