gpt4 book ai didi

android - java.lang.IllegalArgumentException : current should be >= start and <= end 异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:22:00 25 4
gpt4 key购买 nike

我正在尝试在 android 中的按钮上实现日期选择器。但是只要我点击按钮就会弹出错误。但是时间选择器运行良好。这是代码:

mPickDate.setOnClickListener(new View.OnClickListener() {       //Assigning onClickListener to Date Button                                                                  
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});

pickTime.setOnClickListener(new View.OnClickListener() { //Assigning onClickListener to Time Button

@Override
public void onClick(View v) {
showDialog(TIME_DIALOG_ID);

}
});
}

@Override
protected Dialog onCreateDialog(int id) { //Overriding onCreateDialog()
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
case TIME_DIALOG_ID:
return new TimePickerDialog(this,mTimeSetListener,mHour,mMin,true);

}
return null;
}

TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() { //Defining the TimePickerDialog reference variable

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mHour=hourOfDay;
mMin= minute;
updateTime();
}
};

DatePickerDialog.OnDateSetListener mDateSetListener = //Defining the DatePickerDialog reference variable
new DatePickerDialog.OnDateSetListener() {

public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay();
}
};

这是日志:

10-13 16:41:46.878: ERROR/AndroidRuntime(761): FATAL EXCEPTION: main
10-13 16:41:46.878: ERROR/AndroidRuntime(761): java.lang.IllegalArgumentException: current should be >= start and <= end
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.widget.NumberPicker.setCurrent(NumberPicker.java:288)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.widget.DatePicker.updateDaySpinner(DatePicker.java:370)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.widget.DatePicker.updateSpinners(DatePicker.java:356)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.widget.DatePicker.init(DatePicker.java:352)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:127)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:86)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at acb.xiynove.OfflineScreen_ACBActivity.onCreateDialog(OfflineScreen_ACBActivity.java:74)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.app.Activity.onCreateDialog(Activity.java:2482)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.app.Activity.createDialog(Activity.java:882)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.app.Activity.showDialog(Activity.java:2557)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.app.Activity.showDialog(Activity.java:2524)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at acb.xiynove.OfflineScreen_ACBActivity$3.onClick(OfflineScreen_ACBActivity.java:56)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.view.View.performClick(View.java:2485)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.view.View$PerformClick.run(View.java:9080)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.os.Handler.handleCallback(Handler.java:587)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.os.Handler.dispatchMessage(Handler.java:92)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.os.Looper.loop(Looper.java:123)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at java.lang.reflect.Method.invokeNative(Native Method)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at java.lang.reflect.Method.invoke(Method.java:507)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-13 16:41:46.878: ERROR/AndroidRuntime(761): at dalvik.system.NativeStart.main(Native Method)

最佳答案

我遇到了同样的问题,但我找到了解决方案。你应该初始化mYear,mMonth,mDay:

//Init this variables as you wish eg.:
private int mYear = 2010;
private int mMonth = 11;
private int mDay =1;
@Override
protected Dialog onCreateDialog(int id) { //Overriding onCreateDialog()
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
case TIME_DIALOG_ID:
return new TimePickerDialog(this,mTimeSetListener,mHour,mMin,true);

}
return null;
}

关于android - java.lang.IllegalArgumentException : current should be >= start and <= end 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7753309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com