Thursday, December 11, 2014

No source code is available for type *Class*: did you forget to inherit a required module?


If you found the above titled error in your IDE, probably you are facing the most common error for every GWT beginner. The fact is that,  in GWT you are limited to use only some of the Java classes from whole Java API. You cannot simply use all the available classes in Java with GWT. 

Keeping in mind the fact that GWT compiles Java code to JavaScript  there are multiple reasons and limitations from JavaScript side to limit most of the Java features. So GWT is very choosy with Java API classes and you have to use those classes only.

With GWT it is not possible to convert all the Java classes to JavaScript because there are some functional differences with Java and JavaScript. It is not quite possible to achieve all the functional benefits of Java to JavaScript.

For instance, let see two functional differences, why it is not possible to use those Java classes in Javascript.

Instance 1 : java.io.File

You cannot use/do IO operations in Javascript since HTML and Javascript cannot have access to file system. That's the reason GWT restrict io classes of Java to use.

Instance 2 : java.lang.Thread

You cannot use/do multi threading in Javascript since it is single thread model. That's the reason GWT restrict Thread related classes to use.

Like above instances, there are other instances to restrict the usage of many classes from Java. Again coming to the solution part, we can't do anything about the restriction and we have to stick to the available classes. You need not to remember all those classes list. Below is the complete list of subset that GWT can emulate.

Below are the packages support in GWT from JRE.

java.lang
java.lang.annotation
java.math
java.io
java.sql
java.util
java.util.logging.

Even from the above packages you cannot use all the classes. Just go through the below link for complete list of classes GWT support from Java library.

http://www.gwtproject.org/doc/latest/RefJreEmulation.html


When you stumble with the titled error just go through this list and check that you are using the white listed Java classes in GWT or not. If you are not using some other class/classes which are not white listed, you'll end up with the exception/error



Recent post : Why GWT loads slow and tips to load GWT app faster
Post a Comment