java.text.NumberFormat not found

1,149 views
Skip to first unread message

corbinlc

unread,
May 19, 2008, 2:27:58 PM5/19/08
to Google Web Toolkit
From this discussion, it sounds like java.txt.NumberFormat was to be
put in 1.4.

http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/502c228df57d34d9/f308cd3977a8c502?lnk=gst&q=text.numberformat#f308cd3977a8c502

I am using 1.5 M2 and am getting an error that no source code is found
for java.txt.NumberFormat.

Was it never put in 1.4? Is it back out?

Thanks!

Thomas Broyer

unread,
May 19, 2008, 3:13:16 PM5/19/08
to Google Web Toolkit


On May 19, 8:27 pm, corbinlc <corbi...@gmail.com> wrote:
> From this discussion, it sounds like java.txt.NumberFormat was to be
> put in 1.4.
>
> http://groups.google.com/group/Google-Web-Toolkit/browse_thread/threa...
>
> I am using 1.5 M2 and am getting an error that no source code is found
> for java.txt.NumberFormat.

It's actually a GWT-specific class:
http://google-web-toolkit.googlecode.com/svn/javadoc/1.4/com/google/gwt/i18n/client/NumberFormat.html
http://bunsenandbeaker.googlecode.com/svn/javadoc/1.5/com/google/gwt/i18n/client/NumberFormat.html

corbinlc

unread,
May 19, 2008, 3:38:45 PM5/19/08
to Google Web Toolkit
Thanks for your reply, but I am not sure I understand...

I see the documentation you linked to. Not sure what this means. GWT
is fairly new to me. I have code that does this:

import java.text.NumberFormat;
then later on...
private static NumberFormat numFormat = NumberFormat.getInstance();
And I get this error:
No source code is available for type java.text.NumberFormat; did you
forget to inherit a required module?

Are you saying that I need to replace my use of java.text.NumberFormat
with the use of a GWT specific class? If so, what would that look
like?

Thanks!

Jason Essington

unread,
May 19, 2008, 4:06:12 PM5/19/08
to Google-We...@googlegroups.com

What Thomas said is:

You'll want to use the class com.google.gwt.i18n.client.NumberFormat
But to do that, you'll have to add <inherits
name='com.google.com.gwt.i18n.I18N'/> to your gwt.xml file

-jason

corbinlc

unread,
May 19, 2008, 4:21:47 PM5/19/08
to Google Web Toolkit
Thanks for the suggestion... Doing what was suggested results in
this:

Unable to find 'com/google/com/gwt/i18n/I18N.gwt.xml' on your
classpath; could be a typo, or maybe you forgot to include a classpath
entry for source?

I will dig around a little, but if you already know what causes this
issue that would be great!

Jason Essington

unread,
May 19, 2008, 4:28:12 PM5/19/08
to Google-We...@googlegroups.com
or maybe I typed it wrong: com.google.gwt.i81n.I18N

corbinlc

unread,
May 19, 2008, 4:41:08 PM5/19/08
to Google Web Toolkit
Ok, from comparing your two replies, I found this to be correct:
com.google.gwt.i18n.I18N

This didn't help the original errors I was getting though. So, is
java.txt.NumberFormat not supported despite what was written here:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/502c228df57d34d9/f308cd3977a8c502?lnk=gst&q=text.numberformat#f308cd3977a8c502
?
And instead there is a different class that can be included that is
also call NumberFormat, but does not do all the same things?

So, I need to include this new class and modify my code to import it
and use it instead, including modifying any calls to unsupported
methods?

I think I am still trying to figure out if I do or don't need to
modify my code for NumberFormat.getInstance to work as shown in the
brief code snippet above.

Thanks!

Folke

unread,
May 19, 2008, 4:41:35 PM5/19/08
to Google Web Toolkit
java.text.NumberFormat isn't available (yet).
Use com.google.gwt.i18n.client.NumberFormat from the module
com.google.gwt.i18n.I18N.

Jason Essington

unread,
May 19, 2008, 5:05:50 PM5/19/08
to Google-We...@googlegroups.com
That is correct, if a (core) java class isn't in the emulation library:
http://code.google.com/webtoolkit/documentation/jre.html
Then you cannot use it in your client code.

you can always look at the GWT source code in SVN to see what is and
isn't in the emulation library:
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/super/com/google/gwt/emul/

-jason

Thomas Broyer

unread,
May 19, 2008, 7:04:27 PM5/19/08
to Google Web Toolkit


On May 19, 10:41 pm, corbinlc <corbi...@gmail.com> wrote:
> Ok, from comparing your two replies, I found this to be correct:
> com.google.gwt.i18n.I18N
>
> This didn't help the original errors I was getting though.  So, is
> java.txt.NumberFormat not supported despite what was written here:http://groups.google.com/group/Google-Web-Toolkit/browse_thread/threa...
> ?
> And instead there is a different class that can be included that is
> also call NumberFormat, but does not do all the same things?

Yes, because everything has to be rewritten in JavaScript and because
of limitations of GWT (regarding how locales are handled for
instance).

> So, I need to include this new class and modify my code to import it
> and use it instead, including modifying any calls to unsupported
> methods?

Yes, and actually GWT's NumberFormat looks more like
java.text.DecimalFormat than java.text.NumberFormat.

> I think I am still trying to figure out if I do or don't need to
> modify my code for NumberFormat.getInstance to work as shown in the
> brief code snippet above.

JRE's NumberFormat.getInstance().format(variable) is roughly
equivalent to GWT's NumberFormat.getDecimalFormat().format(variable)

Same for getCurrencyInstance vs. getCurrentFormat and
getPercentInstance vs getPercentFormat.

And JRE's new DecimalFormat(format) is roughly equivalent to GWT's
NumberFormat.getFormat(format)

Other differences are in the javadoc.
Reply all
Reply to author
Forward
0 new messages