App crashes during creation DatePickerDialog

General Tech Learning Aids/Tools 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

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
profilepic.png
manpreet 2 years ago

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.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.