StrongSteve, I think you discovered a bug. I tried your code and I am getting a JS error too. Windows.alert() in front of format() removes the error. Hosted mode works either way. It might be a bug compiler's optimization. A one-liner like that is probably inlined by the compiler.
You should log this issue to the GWT issue tracker at http://code.google.com/p/google-web-toolkit/issues/list Yegor On Apr 1, 4:52 am, StrongSteve <[email protected]> wrote: > No one? > > On Mar 25, 11:32 am, StrongSteve <[email protected]> wrote: > > > > > Hello, > > > I experience the following - from my point of view unexplainable - > > behaviour when using the GWT NumberFormat > > (com.google.gwt.i18n.client.NumberFormat). I am using GWT 2.0.3, > > Eclipse Ganymed and IE8/FF3.6. > > > Within my client package I have a static helper class which contains > > the following method: > > > <code> > > > public class Utils { > > ... > > public static final NumberFormat DOUBLE2_FORMAT = > > NumberFormat.getFormat("##########.00"); > > ... > > > public String formatDouble2(double d) { > > return DOUBLE2_FORMAT.format(d); > > } > > > ... > > > } > > > </code> > > > Using the code above I get a javascript error when using the > > formatDouble2 method. Compiling the GWT code in a "detailed" way and > > the javascript error message is something like > > com...i18n.client.positivePrefix is null or not an object. The GUI > > gets stuck and the application is no longer usable. > > > So how did I solve it? > > During debug instrumentalization I found two ways. Unfortunately I can > > not explain either of them - so I was hoping someone can explain me > > why it works! ;) > > > Adding a Window.alert(...) into the formatDouble2 and everything works > > fine. Why!? > > > <code> > > > public class Utils { > > ... > > public static final NumberFormat DOUBLE2_FORMAT = > > NumberFormat.getFormat("##########.00"); > > ... > > > public String formatDouble2(double d) { > > Window.alert("Utils: inside formatDouble2 d=" +d); > > return DOUBLE2_FORMAT.format(d); > > } > > > ... > > > } > > > </code> > > > The solution I am currently using is to only use pattern itself as a > > static member and create the NumerFormat within the method. This works > > too. > > > <code> > > > public class Utils { > > ... > > public static final String DOUBLE2_FORMAT_PATTERN = "##########.00"; > > ... > > > public String formatDouble2(double d) { > > return NumberFormat.getFormat(DOUBLE2_FORMAT_PATTERN).format(d); > > } > > > ... > > > } > > > </code> > > > BTW, changing the public static to private static did not work either. > > > Thanks in Advance for your help! > > Stefan -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
