Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8737135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:26:49+00:00 2026-06-13T10:26:49+00:00

I’m having an IllegalArgumentException when I validate a date on a DatePickerDialog. Here is

  • 0

I’m having an IllegalArgumentException when I validate a date on a DatePickerDialog. Here is the stacktrace:

10-27 19:50:34.700: E/AndroidRuntime(1188): FATAL EXCEPTION: main
10-27 19:50:34.700: E/AndroidRuntime(1188): java.lang.IllegalArgumentException
10-27 19:50:34.700: E/AndroidRuntime(1188):     at java.text.DateFormat.format(DateFormat.java:365)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at java.text.Format.format(Format.java:93)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at com.boka.lesbonscomptes.ActivityMain$1.onDateSet(ActivityMain.java:43)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at android.app.DatePickerDialog.onClick(DatePickerDialog.java:111)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at android.os.Looper.loop(Looper.java:137)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at android.app.ActivityThread.main(ActivityThread.java:4424)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at java.lang.reflect.Method.invokeNative(Native Method)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at java.lang.reflect.Method.invoke(Method.java:511)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-27 19:50:34.700: E/AndroidRuntime(1188):     at dalvik.system.NativeStart.main(Native Method)

and my code

    public class ActivityMain extends Activity {

    //Attributs UI
    private LinearLayout layoutNouvelleDepense = null;
    private Button bDate = null;

    private GregorianCalendar gcDate = null;

    //util
    private SimpleDateFormat sdfAjd = null;
    static final int DATE_DIALOG_ID = 1;


    /*LISTENER*/

    private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
        {
            Toast.makeText(getBaseContext(), "ok",Toast.LENGTH_SHORT).show();
            //La date est calée sur le choix de l'utilisateur
            gcDate.set(year, monthOfYear, dayOfMonth);
            //Le bouton est mis à jour avec la date choisie
            bDate.setText(sdfAjd.format(gcDate));
        }
    };  

    private OnClickListener oclBoutonDate = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DATE_DIALOG_ID);     
        }
    };      


    /*METHODES*/
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        layoutNouvelleDepense = (LinearLayout) LinearLayout.inflate(this,R.layout.nouvelle_depense, null);
        bDate = (Button) layoutNouvelleDepense.findViewById(R.id.bDate);

        bDate.setOnClickListener(oclBoutonDate);

        gcDate = new GregorianCalendar();
        sdfAjd = new SimpleDateFormat("EEEE dd/MM/yyyy", Locale.getDefault());

        bDate.setText(sdfAjd.format(gcDate.getTime()));

        setContentView(layoutNouvelleDepense);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @SuppressWarnings("static-access")
    @Override    
    protected Dialog onCreateDialog(int id) 
    {
        System.out.println("DATE = " + gcDate.get(GregorianCalendar.YEAR) + "/" + gcDate.get(GregorianCalendar.MONTH) + "/" +  gcDate.get(GregorianCalendar.DAY_OF_MONTH));
         return new DatePickerDialog(this, mDateSetListener, gcDate.get(GregorianCalendar.YEAR), gcDate.get(GregorianCalendar.MONTH), gcDate.get(GregorianCalendar.DAY_OF_MONTH));
    }
}

I have no issues in creating the dialog, and the date is correctly initialized when the dialog is displayed.

No matter the date chosen, the IllegalArgumentException is raised.

I’ve been looking for an answer since quite a while, but all the similar posts are about excepetion raised at the creation of the dialog, not the validation of the date.

Can you please help me find out what’s going on ?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:26:51+00:00Added an answer on June 13, 2026 at 10:26 am

    In your OnDateSetListener add getTime() to your format command:

    bDate.setText(sdfAjd.format(gcDate.getTime()));
    

    The difference is that GregorianCalendar#getTime() returns a Date object and calls SimpleDateFormat#format(Date) which, as you know, works fine in your onCreate() method.

    But format(gcDate) by itself calls the generic SimpleDateFormat#format(Object) method which throws the exception because this format() does not understand the Date object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.