当我尝试调用DatePickerDialog应用程序崩溃时,尽管如此,我按照相同的方式调用TimePickerDialog,并且它可以正常工作。任何建议。
我检查了一个DatePickerDialog的例子,它与我所遵循的一样。
I STILL Have the Same Problem
代码:
public class PickerActivity extends Activity{
int hour, minute;
int year,month, day;
static final int timePickerId = 0;
static final int datePickerId = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.picker);
//showDialog(timePickerId);
showDialog(datePickerId);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
/*case timePickerId:
return new TimePickerDialog(
this, mTimeSetListener, hour, minute, true);*/
case datePickerId:
return new DatePickerDialog(
this, mDateSetListener, year, month, day);
}
return null;
}
private DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener()
{
public void onDateSet(DatePicker view, int Year, int monthOfYear,
int dayOfMonth)
{
year = Year;
month = monthOfYear;
day = dayOfMonth;
Toast.makeText(getBaseContext(),
"You have selected : " + (month) +
"/" + day + "/" + year,
Toast.LENGTH_SHORT).show();
}
};
logcat的:
03-06 17:52:40.600: E/AndroidRuntime(819): FATAL EXCEPTION: main
03-06 17:52:40.600: E/AndroidRuntime(819): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidbook.DatePicker/com.androidbook.DatePicker.PickerActivity}: java.lang.IllegalArgumentException: current should be >= start and <= end
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.os.Looper.loop(Looper.java:130)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-06 17:52:40.600: E/AndroidRuntime(819): at java.lang.reflect.Method.invokeNative(Native Method)
03-06 17:52:40.600: E/AndroidRuntime(819): at java.lang.reflect.Method.invoke(Method.java:507)
03-06 17:52:40.600: E/AndroidRuntime(819): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-06 17:52:40.600: E/AndroidRuntime(819): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-06 17:52:40.600: E/AndroidRuntime(819): at dalvik.system.NativeStart.main(Native Method)
03-06 17:52:40.600: E/AndroidRuntime(819): Caused by: java.lang.IllegalArgumentException: current should be >= start and <= end
03-06 17:52:40.600: E/AndroidRuntime(819): at android.widget.NumberPicker.setCurrent(NumberPicker.java:288)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.widget.DatePicker.updateDaySpinner(DatePicker.java:397)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.widget.DatePicker.updateSpinners(DatePicker.java:383)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.widget.DatePicker.init(DatePicker.java:379)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:127)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:86)
03-06 17:52:40.600: E/AndroidRuntime(819): at com.androidbook.DatePicker.PickerActivity.onCreateDialog(PickerActivity.java:39)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.Activity.onCreateDialog(Activity.java:2482)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.Activity.createDialog(Activity.java:882)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.Activity.showDialog(Activity.java:2557)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.Activity.showDialog(Activity.java:2524)
03-06 17:52:40.600: E/AndroidRuntime(819): at com.androidbook.DatePicker.PickerActivity.onCreate(PickerActivity.java:27)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-06 17:52:40.600: E/AndroidRuntime(819): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-06 17:52:40.600: E/AndroidRuntime(819): ... 11 more
03-06 17:54:56.370: E/AndroidRuntime(852): FATAL EXCEPTION: main
03-06 17:54:56.370: E/AndroidRuntime(852): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidbook.DatePicker/com.androidbook.DatePicker.PickerActivity}: java.lang.IllegalArgumentException: current should be >= start and <= end
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.os.Looper.loop(Looper.java:130)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-06 17:54:56.370: E/AndroidRuntime(852): at java.lang.reflect.Method.invokeNative(Native Method)
03-06 17:54:56.370: E/AndroidRuntime(852): at java.lang.reflect.Method.invoke(Method.java:507)
03-06 17:54:56.370: E/AndroidRuntime(852): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-06 17:54:56.370: E/AndroidRuntime(852): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-06 17:54:56.370: E/AndroidRuntime(852): at dalvik.system.NativeStart.main(Native Method)
03-06 17:54:56.370: E/AndroidRuntime(852): Caused by: java.lang.IllegalArgumentException: current should be >= start and <= end
03-06 17:54:56.370: E/AndroidRuntime(852): at android.widget.NumberPicker.setCurrent(NumberPicker.java:288)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.widget.DatePicker.updateDaySpinner(DatePicker.java:397)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.widget.DatePicker.updateSpinners(DatePicker.java:383)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.widget.DatePicker.init(DatePicker.java:379)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:127)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:86)
03-06 17:54:56.370: E/AndroidRuntime(852): at com.androidbook.DatePicker.PickerActivity.onCreateDialog(PickerActivity.java:39)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.Activity.onCreateDialog(Activity.java:2482)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.Activity.createDialog(Activity.java:882)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.Activity.showDialog(Activity.java:2557)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.Activity.showDialog(Activity.java:2524)
03-06 17:54:56.370: E/AndroidRuntime(852): at com.androidbook.DatePicker.PickerActivity.onCreate(PickerActivity.java:27)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-06 17:54:56.370: E/AndroidRuntime(852): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-06 17:54:56.370: E/AndroidRuntime(852): ... 11 more
03-06 17:55:12.010: E/AndroidRuntime(886): FATAL EXCEPTION: main
03-06 17:55:12.010: E/AndroidRuntime(886): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidbook.DatePicker/com.androidbook.DatePicker.PickerActivity}: java.lang.IllegalArgumentException: current should be >= start and <= end
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.os.Looper.loop(Looper.java:130)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-06 17:55:12.010: E/AndroidRuntime(886): at java.lang.reflect.Method.invokeNative(Native Method)
03-06 17:55:12.010: E/AndroidRuntime(886): at java.lang.reflect.Method.invoke(Method.java:507)
03-06 17:55:12.010: E/AndroidRuntime(886): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-06 17:55:12.010: E/AndroidRuntime(886): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-06 17:55:12.010: E/AndroidRuntime(886): at dalvik.system.NativeStart.main(Native Method)
03-06 17:55:12.010: E/AndroidRuntime(886): Caused by: java.lang.IllegalArgumentException: current should be >= start and <= end
03-06 17:55:12.010: E/AndroidRuntime(886): at android.widget.NumberPicker.setCurrent(NumberPicker.java:288)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.widget.DatePicker.updateDaySpinner(DatePicker.java:397)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.widget.DatePicker.updateSpinners(DatePicker.java:383)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.widget.DatePicker.init(DatePicker.java:379)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:127)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:86)
03-06 17:55:12.010: E/AndroidRuntime(886): at com.androidbook.DatePicker.PickerActivity.onCreateDialog(PickerActivity.java:39)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.Activity.onCreateDialog(Activity.java:2482)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.Activity.createDialog(Activity.java:882)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.Activity.showDialog(Activity.java:2557)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.Activity.showDialog(Activity.java:2524)
03-06 17:55:12.010: E/AndroidRuntime(886): at com.androidbook.DatePicker.PickerActivity.onCreate(PickerActivity.java:27)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-06 17:55:12.010: E/AndroidRuntime(886): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-06 17:55:12.010: E/AndroidRuntime(886): ... 11 more
03-06 17:58:35.520: E/AndroidRuntime(920): FATAL EXCEPTION: main
03-06 17:58:35.520: E/AndroidRuntime(920): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidbook.DatePicker/com.androidbook.DatePicker.PickerActivity}: java.lang.IllegalArgumentException: current should be >= start and <= end
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.os.Looper.loop(Looper.java:130)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-06 17:58:35.520: E/AndroidRuntime(920): at java.lang.reflect.Method.invokeNative(Native Method)
03-06 17:58:35.520: E/AndroidRuntime(920): at java.lang.reflect.Method.invoke(Method.java:507)
03-06 17:58:35.520: E/AndroidRuntime(920): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-06 17:58:35.520: E/AndroidRuntime(920): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-06 17:58:35.520: E/AndroidRuntime(920): at dalvik.system.NativeStart.main(Native Method)
03-06 17:58:35.520: E/AndroidRuntime(920): Caused by: java.lang.IllegalArgumentException: current should be >= start and <= end
03-06 17:58:35.520: E/AndroidRuntime(920): at android.widget.NumberPicker.setCurrent(NumberPicker.java:288)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.widget.DatePicker.updateDaySpinner(DatePicker.java:397)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.widget.DatePicker.updateSpinners(DatePicker.java:383)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.widget.DatePicker.init(DatePicker.java:379)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:127)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:86)
03-06 17:58:35.520: E/AndroidRuntime(920): at com.androidbook.DatePicker.PickerActivity.onCreateDialog(PickerActivity.java:38)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.Activity.onCreateDialog(Activity.java:2482)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.Activity.createDialog(Activity.java:882)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.Activity.showDialog(Activity.java:2557)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.Activity.showDialog(Activity.java:2524)
03-06 17:58:35.520: E/AndroidRuntime(920): at com.androidbook.DatePicker.PickerActivity.onCreate(PickerActivity.java:27)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-06 17:58:35.520: E/AndroidRuntime(920): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-06 17:58:35.520: E/AndroidRuntime(920): ... 11 more
答案 0 :(得分:3)
java.lang.IllegalArgumentException:current应该是&gt; = start和&lt; = end
看起来您没有将日,月,年设置为正确的值。
答案 1 :(得分:2)
年或月具有非法价值。请尝试使用urdate.getYear() + 1900
,因为年份是从1900年开始。urdate.getMonth
的月份范围是0-11。