GWT - did you forget to inherit a required module?
Asked Answered
S

2

21

In my GWT application, on the client side Java file, I have written a line to print the Locale:

System.out.println(Locale.getDefault());

Here Locale is an instance of java.util.Locale.

I'm getting an exception: 09:31:53.656 [ERROR] [stockwatcher] Line 167 No source code is available for type java.util.Locale; did you forget to inherit a required module?

Surprisingly, in this class I've also used java.util.ArrayList and java.util.Date but I did not get any exception for those classes.

What am i doing wrong here?

Smoking answered 7/4, 2011 at 4:19 Comment(0)
C
45

The client-side of GWT does not have access to the whole Java API. Java.util.Locale is one of them. You can't use or even import it on the client-side. But you can definitely use it on the server-side of GWT. You can find the list of classes that can be used at client-side here.

Churchly answered 7/4, 2011 at 6:4 Comment(2)
Is there any way to workaround this issue? How can I use some classes which are not present in above list?Harlan
@mmk, as per the best of my knowledge, there's no workaround to this issue. You can just try importing the class you want to use. If you get this error, you can't use it.Churchly
C
12

In addition to information in RAS's answer, you could use GWT's class LocaleInfo to obtain information about available locales or current locale.

System.out.println(LocaleInfo.getCurrentLocale());

Hope this helps!

Cockroach answered 7/4, 2011 at 13:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.