Question

I'm completely new to programming on the Android platform but I'm interested in learning more of it. At the moment I'm doing this with the aid of a step by step handbook. Just to get myself familiar with the programming environment. I have knowledge of the Java language although I would not go as far by saying I'm good at it.

As for the problem, what I'm creating is a simple trivia game for Android devices. On a settings screen I am using a DatePickerDialog for the users birthday. Only when I run it on my Android device (Samsung Galaxy S i9000) or an emulator it crashes when trying to popup the DatePickerDialog.

The code I use is:

final TextView dob = (TextView) findViewById(R.id.TextView_DOB_Info);
DatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        Time dateOfBirth = new Time();
        dateOfBirth.set(dayOfMonth, monthOfYear, year);
        long dtDob = dateOfBirth.toMillis(true);
        dob.setText(DateFormat.format("MMMM dd, yyyy", dtDob));
        Editor editor = mGameSettings.edit();
        editor.putLong(GAME_PREFERENCES_DOB, dtDob);
        editor.commit();
    }
}, 0, 0, 0);
return dateDialog;

Can anyone see if I'm doing something wrong here? When running I get an IllegalArgumentException in that method. I'm using Eclipse to program for Android, but I'm also fairly new to the program (I'm more familiar with Netbeans), I'm still trying to figure out how to properly debug through the Android app.

If anyone can help it will be greatly appreciated! Kind Regards, Floris

EDIT: As per request I added the LogCat lines:

09-16 18:42:22.386: ERROR/AndroidRuntime(20074): FATAL EXCEPTION: main
09-16 18:42:22.386: ERROR/AndroidRuntime(20074): java.lang.IllegalArgumentException: current should be >= start and <= end
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.widget.NumberPicker.setCurrent(NumberPicker.java:362)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.widget.DatePicker.updateDaySpinner(DatePicker.java:487)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.widget.DatePicker.updateSpinners(DatePicker.java:471)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.widget.DatePicker.init(DatePicker.java:467)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.app.DatePickerDialog.<init>(DatePickerDialog.java:154)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.app.DatePickerDialog.<init>(DatePickerDialog.java:113)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at com.androidbook.triviaquiz.QuizSettingsActivity.onCreateDialog(QuizSettingsActivity.java:404)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.app.Activity.onCreateDialog(Activity.java:2482)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.app.Activity.createDialog(Activity.java:882)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.app.Activity.showDialog(Activity.java:2557)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.app.Activity.showDialog(Activity.java:2524)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at com.androidbook.triviaquiz.QuizSettingsActivity$4.onClick(QuizSettingsActivity.java:367)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.view.View.performClick(View.java:2538)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.view.View$PerformClick.run(View.java:9152)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.os.Handler.handleCallback(Handler.java:587)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.os.Looper.loop(Looper.java:123)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at android.app.ActivityThread.main(ActivityThread.java:3687)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at java.lang.reflect.Method.invokeNative(Native Method)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at java.lang.reflect.Method.invoke(Method.java:507)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
09-16 18:42:22.386: ERROR/AndroidRuntime(20074):     at dalvik.system.NativeStart.main(Native Method)
09-16 18:42:22.414: ERROR/(14248): Dumpstate > /data/log/dumpstate_app_error

As I'm reading through it now I notice the problem is in the NumberPicker class. Just to be sure, what is the meaning of the number he is expecting here?

Was it helpful?

Solution

I've never used DatePickerDialog but as far as I can tell, you're using 0, 0, 0 as the year, month of year and day of month parameters. Set these to be something logical like 2011, 9, 16 and see if that helps.

EDIT Actually you may have to use 10 for September as I think it conforms to the 0-11 month numbers used by Calendar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top