2013-06-24 59 views
0

我創建了一個日期選擇器,如圖所示。它顯示當我在標籤上運行該程序,但當我嘗試它的手機(HTC Glacier)應用程序崩潰時,我可以找出我錯過了什麼東西。請幫幫我。由於enter image description here在android中的datepicker錯誤

這裏是我的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) 

這裏是我的主要活動代碼,日期選擇

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

.... 
+0

問題檢查這些東西正常.. –

回答

0

你的init代碼是相當的很奇怪,並使用不推薦的方法。 試試這個:在設備和您的代碼與當前日期

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 
     } 
}); 
+0

感謝@Zarokka,它的作品! – lolliloop

1

你有沒有初始化的yearmonthOfYeardayOfMonth

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