BUG: "java.lang.IllegalArgumentException" Error Message When You Use the DateFormat and NumberFormat Instance Methods

SYMPTOMS
You are working in a multilanguage environment, such as Arabic, Belarusian, Bulgarian, Catalan, Czech, Danish, or German. When you call the DateFormat instance method or the NumberFormat instance method, you receive the following exception error message:
java.lang.IllegalArgumentException: Could not create FormatInfo for Locale
Note You receive this error message when you try to create a DateFormat instance by using any of the following methods:
  • getDateInstance
  • getTimeInstance
  • getDateTimeInstance
You receive this error message when you try to create a NumberFormat instance by using one of the following methods:
  • getInstance
  • getPercentInstance
  • getCurrencyInstance
CAUSE
This problem occurs because DateFormat and NumberFormat are not installed for all locales. When you use a locale that does not have DateFormat and NumberFormat installed, the methods that are listed in the "Symptoms" section cannot retrieve region-specific format information.
RESOLUTION
To resolve this problem, use a locale that has NumberFormat and DateFormat installed. You can use the NumberFormat.getAvailableLocales method or the DateFormat.getAvailableLocales method to get the set of locales that have NumberFormat and DateFormat installed.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. In the New Project dialog box, click Visual J# Projects under Project Types, click Console Application under Templates, and then click OK.
  4. In Class1.jsl, replace the existing code with following sample code:
    import java.text.*;import java.util.*;public class Class1{	// Default Constructor	public Class1()	{	}	// Testing the instance methods of NumberFormat	public void TestNumberFormatMethods(Locale loc)	{		long number = 609607; // A sample number for formatting		// Testing the getInstance() method		try		{			String myString = NumberFormat.getInstance(loc).format(number);		}		catch(Exception ex)		{			ex.printStackTrace();		}		// Testing the getCurrencyInstance() method		try		{			String myString = NumberFormat.getCurrencyInstance(loc).format(number);		}		catch(Exception ex)		{			ex.printStackTrace();		}		// Testing the getPercentInstance() method		try		{			String myString = NumberFormat.getPercentInstance(loc).format(number);		}		catch(Exception ex)		{			ex.printStackTrace();		}	}	// Testing the instance methods of DateFormat	public void TestDateFormatMethods(Locale loc, int style, String styleName)	{		Date date = new Date(1975,11,12); // A sample date for formatting		// Testing the getDateInstance() method		try		{			String myString=DateFormat.getDateInstance(style, loc).format(date);		}		catch(Exception ex)		{			ex.printStackTrace();		}		// Testing the getTimeInstance() method		try		{			String myString=DateFormat.getTimeInstance(style, loc).format(date);		}		catch(Exception ex)		{			ex.printStackTrace();		}		// Testing the getDateTimeInstance() method		try		{			String myString=DateFormat.getDateTimeInstance(style,style,loc).format(date);		}		catch(Exception ex)		{			ex.printStackTrace();		}			}		// Main method	public static void main(String[] args)	{		Locale loc = new Locale("de", "");		Class1 myObject = new Class1();				try		{			System.out.println(loc.getDisplayName()+":");			System.out.println("-------------------");			myObject.TestDateFormatMethods(loc, DateFormat.DEFAULT, "DEFAULT");			myObject.TestNumberFormatMethods(loc);		}		finally 		{			System.Console.Read();		}	}}
  5. On the Debug menu, click Start.
REFERENCES
For more information about language support constants, visit the following Microsoft Web site:
Properties

Article ID: 818431 - Last Review: 05/16/2007 02:08:42 - Revision: 1.3

Microsoft Visual J# .NET 2003 Standard Edition

  • kberrmsg kblocalization kbformat kbunicode kbjava kbdatetime kbbug KB818431
Feedback