Microsoft KB Archive/818431

= BUG: &quot;java.lang.IllegalArgumentException&quot; Error Message When You Use the DateFormat and NumberFormat Instance Methods =

Article ID: 818431

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft Visual J# .NET 2003 Standard Edition

-



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

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 &quot;Symptoms&quot; 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.



Steps to Reproduce the Behavior
 Start Visual Studio .NET. On the File menu, point to New, and then click Project. In the New Project dialog box, click Visual J# Projects under Project Types, click Console Application under Templates, and then click OK.  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(&quot;de&quot;, &quot;&quot;); Class1 myObject = new Class1; try {           System.out.println(loc.getDisplayName+&quot;:&quot;); System.out.println(&quot;---&quot;); myObject.TestDateFormatMethods(loc, DateFormat.DEFAULT, &quot;DEFAULT&quot;); myObject.TestNumberFormatMethods(loc); }       finally {           System.Console.Read; }   } }  On the Debug menu, click Start.</ol>

<div class="references_section">