android对话框中的非法参数异常

时间:2010-09-09 04:59:36

标签: android

我正在使用此代码显示警告对话框...当我点击确定按钮时,它应显示日期选择器..

protected Dialog onCreateDialog(int id) {
    switch (id) {
    case TIME_DIALOG_ID:
        return new TimePickerDialog(ListReminderActivity.this,
                mTimeSetListener, mHour, mMinute, false);
    case DATE_DIALOG_ID:
        return new DatePickerDialog(ListReminderActivity.this,
                mDateSetListener, mYear, mMonth, mDay);
    case DESCRIPTION_DIALOG_ID:
        return new AlertDialog.Builder(ListReminderActivity.this).setTitle(
                "Add Reminder").setView(description).setPositiveButton(
                R.string.add_alert_ok,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                            int whichButton) {
                        ListReminderActivity.this
                                .dismissDialog(DESCRIPTION_DIALOG_ID);
                        ListReminderActivity.this
                                .removeDialog(DESCRIPTION_DIALOG_ID);
                        ListReminderActivity.this
                                .showDialog(DATE_DIALOG_ID);
                    }
                }).setNegativeButton(R.string.add_alert_cancel,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                            int whichButton) {
                        ListReminderActivity.this
                                .dismissDialog(DESCRIPTION_DIALOG_ID);
                        ListReminderActivity.this
                                .removeDialog(DESCRIPTION_DIALOG_ID);
                    }
                }).create();
    }
    return null;
}

但问题是..当我按下确定按钮

时,我得到了例外

例外是......

    09-09 10:30:48.941: ERROR/AndroidRuntime(1189): FATAL EXCEPTION: main
09-09 10:30:48.941: ERROR/AndroidRuntime(1189): java.lang.IllegalArgumentException: current should be >= start and <= end
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.widget.NumberPicker.setCurrent(NumberPicker.java:288)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.widget.DatePicker.updateDaySpinner(DatePicker.java:364)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.widget.DatePicker.updateSpinners(DatePicker.java:350)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.widget.DatePicker.init(DatePicker.java:346)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.app.DatePickerDialog.<init>(DatePickerDialog.java:124)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.app.DatePickerDialog.<init>(DatePickerDialog.java:83)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at com.app.reminder.ListReminderActivity.onCreateDialog(ListReminderActivity.java:149)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.app.Activity.onCreateDialog(Activity.java:2472)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.app.Activity.createDialog(Activity.java:881)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.app.Activity.showDialog(Activity.java:2547)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.app.Activity.showDialog(Activity.java:2514)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at com.app.reminder.ListReminderActivity$3.onClick(ListReminderActivity.java:164)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.os.Looper.loop(Looper.java:123)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at java.lang.reflect.Method.invokeNative(Native Method)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at java.lang.reflect.Method.invoke(Method.java:521)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-09 10:30:48.941: ERROR/AndroidRuntime(1189):     at dalvik.system.NativeStart.main(Native Method)

4 个答案:

答案 0 :(得分:9)

你知道月份字段是零 - 从零开始吗?确保月份值不超过11​​!我得到完全相同的消息,因为我一个月使用12,这就是获得此异常的原因。

答案 1 :(得分:5)

如您在日志中看到的错误所示,您的mYear,mMonth或mDay值之一无效。

答案 2 :(得分:0)

将月份字段值设置为X的想法是将其设置为X%12(模数),因此您确定不会超过自动化值。 小时和分钟相同。 干杯。 查尔斯。

答案 3 :(得分:-2)

您必须更改mY年,月,日值。月份是0-11。 确保您的值在

范围内