0

如图所示,我创建了一个日期选择器。当我在选项卡上运行程序时它会出现,但是当我尝试使用手机(HTC Glacier)时应用程序崩溃,我可以找出我错过了什么。请帮帮我。谢谢在此处输入图像描述

这是我的日志:

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)

这是我在日期选择器的主要活动中的代码

 ....
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) {
}
    });

....
4

2 回答 2

1

您是否初始化了year,monthOfYeardayOfMonth

private int mYear = 2012;
private int mMonth = 12;
private int mDay =12;
于 2013-06-24T09:02:12.563 回答
1

您的初始化代码很奇怪,并且使用了不推荐使用的方法。尝试这个:

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
      }
});
于 2013-06-24T09:18:35.030 回答