1

Problem- My application is used in a production environment across a few hundred computers. The issue arose after installing some new computers and finding out that my application was crashing on ONLY the new computers. The new computers came with JAVA v8u5, in attempts to fix the issue I also installed v7u55 (I thought it might be a versioning issue). NOTE* I'm compiling using JDK v7u45 **

Root Cause- The failing code is a call to the Calendar.getDisplayName(int, int, Locale)

Code That is failing:

        System.out.println("Getting calendar instance");
        Calendar instanceCalendarObj = Calendar.getInstance();
        String date = instanceCalendarObj.getDisplayName(Calendar.MONTH, 0, Locale.ENGLISH);
        date = date.concat(" "+String.valueOf(instanceCalendarObj.get(Calendar.DAY_OF_MONTH)));
        date = date.concat(", "+String.valueOf(instanceCalendarObj.get(Calendar.YEAR)));
        JOptionPane.showMessageDialog(this, date);

Error Message:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException
    at java.util.Calendar.checkDisplayNameParams(Unknown Source)
    at java.util.Calendar.getDisplayName(Unknown Source)

Any help would be greatly appreciated, even if its just a workaround.

Tarod
  • 6,732
  • 5
  • 44
  • 50
  • possible duplicate of [IllegalArgumentException or NullPointerException for a null parameter?](http://stackoverflow.com/questions/3881/illegalargumentexception-or-nullpointerexception-for-a-null-parameter) – Mogsdad Sep 01 '15 at 15:07

1 Answers1

2

You pass a wrong parameter to the getDisplayName() method.

The second parameter is the style, whose possible values are Calendar.SHORT and Calendar.LONG. Use these constants as seen below:

Calendar c = Calendar.getInstance();
c.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.ENGLISH);
c.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH);

Btw, the constant values for Calendar.SHORT and Calendar.LONG are 1 and 2 (and you passed 0 in your code). But always use the constant names and not their values!

icza
  • 389,944
  • 63
  • 907
  • 827