GWT Deferred binding failed for custom class: No class matching "..." in urn:import: - class

I am developing a couple of custom widgets that I would like to be able to use with UiBinder. Unfortunately I keep wasting my life away with chasing down the following error:
No class matching "..." in urn:import:...
This seems to be the catch-all exception that is thrown any time there is any error in the class that prevents the GWT compiler from processing it. This includes anything in the class's entire dependency tree.
To save myself and anyone of you who is running into the same issue some time and pain, let's compile a list here of the most unexpected and hard to find causes for this. I'll start with my latest one, which has made me decide to post this here.

I was using a CellList thusly:
private static RelationshipViewerUiBinder uiBinder = GWT.create(RelationshipViewerUiBinder.class);
#UiField(provided=true)
CellList<String> prioritisedDisplay;
public RelationshipViewer() {
prioritisedDisplay = new CellList<>(new TextCell());
initWidget(uiBinder.createAndBindUi(this));
}
note the Java 7 style <> on the CellList. Despite my IDE's protestations to the contrary, it turns out you DO need to explicitly say CellList< String> in that new call, or it wont compile and all you get is the above mentioned error. Thanks by the way, the existance of this question prompted me to scrutinise my code and probably saved me a couple of hours! This fixed it:
private static RelationshipViewerUiBinder uiBinder = GWT.create(RelationshipViewerUiBinder.class);
#UiField(provided=true)
CellList<String> prioritisedDisplay;
public RelationshipViewer() {
prioritisedDisplay = new CellList<String>(new TextCell());
initWidget(uiBinder.createAndBindUi(this));
}

I had written a component that used the GWT JSON functionality, but hadn't imported com.google.gwt.json.JSON into the module.
Thanks to your message here, this was only 2 hours down the drain...

I wrote a helper-class that this widget uses somewhere deep inside its dependency tree.
For this helper-class, I told Eclipse to auto-generate the hashCode() and equals(...) functions. The class contained a field of type double, for which Eclipse generates code that uses Double.doubleToLongBits().
Turns out GWT does not implement this method on its version of Double. But of course, neither does Eclipse detect this as a possible compile-error, nor does it cause any issues in Dev Mode if I use the widget inside the GWT-App's Java code rather than inside UiBinder.
3 hours down the drain... Great... Yay for helpful error messages.
UPDATE:
As of GWT 2.5.0 (RC1) GWT now supports Double.doubleToLongBits() rendering this particular error obsolete, but the general error mechanism of a missing JRE emulation remains and will probably manifest itself in a similarly unhelpful way.

I was trying to use a GwtQuery DragAndDropCellTree in a UiBinder .ui.xml, which was impossible as DragAndDropCellTree has no zero-arg constructor.
See more details

Related

Reuse PDE' s ManifestEditor and meet NullPointerException

1.what we are planning to do :
Reuse the ManifestEditor to open the MANIFEST.MF file, and add our features to the first OverviewPage.
2.what we already have known and done :
It's dangerous to use the internal classes and APIs, so we create a ManifestEditorNew which extends ManifestEditor.
import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
import org.eclipse.pde.internal.ui.editor.plugin.OverviewPage;
public class TheNewManifestEditor extends ManifestEditor{
//it's strange that the default fist page is not the OverviewPage,so we override this method
#Override
protected String computeInitialPageId() {
return OverviewPage.PAGE_ID;
}
}
3.what Exception we meet :
The NullPointerException.
Once our TheNewManifestEditor gained focus, the give us an NPE, but we can not find ant clues which caused this.
You probably need to called super.computeInitialPageId() because it looks like it does some set up.
Note: The reason the overview page is not always shown is because the editor remembers the the last page you looked at and shows you that. It will default to the overview page the first time the manifest is edited.
Just extending an internal class does not remove the fact that you are using internal Eclipse classes which violates the Eclipse API Rules of Engagement. Internal classes can and do change and sometimes even disappear altogether, you are likely to have a lot of trouble when moving between Eclipse releases.

create and return gwt widget from java code

I am new to GWT and I need to reslove this problem. I need to create a widget with gwt-links. To make it happened, I need to fetch some data from an ontology, and then based on the result, create the graph. The problem is that, when I mix java code with gwt code it doesn't want to compile.
The question is, how do I create a widged explained above that will be placed in a http page?
The code looks like this now :
public class Example1 {
#Override
public void draw() {
// Create the elements
String ontology = Ontology.get(1);
Widget labelHello = new BoxLabel(ontology);
controller.addWidget(labelHello,25,115);
// Add DnD logic
PickupDragController dragController = new PickupDragController(controller.getView(), true);
dragController.makeDraggable(labelHello);
}
public Widget asWidget() {
return controller.getView();
}
}
the Ontology.get() doesn't want to compile.
GWT can't compile just any java code.
These are the packages that are emulated by GWT: pls read
The code that can't be translated to javascript, (the stuff that is not emulated) you must handle on the server side.
GWT projects uses three packages (by default)
com.myapp.client
com.myapp.shared
com.myapp.server
By default everything within the shared and client package will be compiled to JavaScript.
Every Class, which is imported into a Class, which is inside the shared and client package must be:
emulated by GWT
Compilable to GWT (and inside the client or shared package)
Compilable to GWT (and the package must be whitelists in *.gwt.xml)
Uf you code ISolver can be compiled to JavaScript you will have to create a module.gwt.xml and inheritt your project from this module. This may enable the GWT-compiler to compile ISolver (and its implementation) to JavaScript.
If your code can't be compiled to GWT you will have to write a remote-service to make the calculation.
I don't really want to compile the code to javascript. All i want to do is to create a GWT widget ( which is a graph).
To create the widget, I need to do some calculations and repository fetch. I dont want to translate it( repository fetching), I just need to use it in order to create the model of the graph.
Basically, this is something I want to do:
String l = Repository.getLabel(); // Some advanced calculations that use many JavaSE classes;
GWTWidget widget = new GWTWidget(l); // widget, that will be displayed on a page.
but when I put something in method onModuleLoad it doesn't compile.
This is probably a simple question, but I'm not really related with GWT and I'm forced to remake someone's work.
public void onModuleLoad() {
System.out.println("tes");
VerticalPanel mainPanel = new VerticalPanel();
RootPanel.get().add(mainPanel);
//
ISolver solver = null;
System.out.println("TEST2");
}
ERROR: Line 53: No source code is available for type pr.ISolver; did you forget to inherit a required module?
ERROR: Unable to find type 'client.Link'
ERROR: Hint: Previous compiler errors may have made this type unavailable
and other lines sthat start with " No source code..".
ISolver is an interface, but I dont want to translate it. I want to use it for calculations.

How to use GWT SerializationStreamFactory

I am trying to serialize a object in GWT using SerializationFactory, but I am not able to get it working. Here is the sample code of my POC:
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.client.rpc.SerializationStreamFactory;
import com.google.gwt.user.client.rpc.SerializationStreamReader;
import com.google.gwt.user.client.rpc.SerializationStreamWriter;
...........
Some code here....
.........
......
SerializationStreamFactory factory = (SerializationStreamFactory) GWT.create(MyClass.class);
SerializationStreamWriter writer = factory.createStreamWriter();
try {
writer.writeObject(new MyClass("anirudh"));
String value = writer.toString();
SerializationStreamReader reader = factory.createStreamReader(value);
MyClass myObj = (MyClass) reader.readObject();
System.out.println(myObj.getName());
} catch (SerializationException e) {
e.printStackTrace();
}
It gave me the following exception
Caused by: java.lang.RuntimeException: Deferred binding failed for 'com.anirudh..client.MyClass' (did you forget to inherit a required module?)
also in my code the class whose object I am trying to serialize implements IsSerializable
MyClass implements IsSerializable
I don't want to use GWT Auto-Bean framework because it does not fit my use case. Also I am not using GWT-RPC framework and right now I am quite adamant about using SerializationStreamFactory :D because I seriously want to know how this thing works.
Can anyone share a working example of SerializationStreamFactory or help me out pointing any mistake(s) I did.
Thanks in advance
SerializationStreamFactory factory = (SerializationStreamFactory) GWT.create(MyClass.class);
What are you expecting this line to do? GWT will attempt to find a replace-with or generate-with rule that matches this class (either when-type-assignable or when-type-is), or failing that will attempt to invoke a zero-arg constructor on MyClass, effectively new MyClass(). Is this what you are expecting?
The selected exception you've pasted suggests that MyClass may not be on the source path that GWT has been given to compile from, but the full error log will provide more information.
It looks as though you are trying to mimic the generated RPC code, where a *Async rpc interface would be implemented by code that extends from com.google.gwt.user.client.rpc.impl.RemoteServiceProxy (which implements SerializationStreamFactory). That base implementation is extended further to initialize several fields such as the com.google.gwt.user.client.rpc.impl.Serializer instance, actually responsible for serializing and deserializing object streams.
Serializers are created (by default) from the base class of com.google.gwt.user.client.rpc.impl.SerializerBase, through the rebind class com.google.gwt.user.rebind.rpc.TypeSerializerCreator. If you've build your own generator for MyClass, you should be kicking this off to get the work done as ProxyCreator already should be doing.
Remember when building your own serialization/deserialization mechanism that you need to decide which types can be marshalled within this system - if you open it to all types, then you will need to generate FieldSerializer types for all possible objects on the source path. This will greatly expand the size of your compiled code.
If your main goal is learning how this 'magic' works, dig into the generators and associated code that live in the com.google.gwt.user.rebind.rpc package. There are other libraries that leverage these ideas such as the gwt-atmosphere project (see https://github.com/Atmosphere/atmosphere to get started). Also review the generated code that GWT creates when it builds a 'tradition' RPC interface.

How do you handle instantiation of Messages classes in GWT?

I have a question on how you usually instantiate GWT Messages. I usually do this:
private static final GenericMessages GENERIC_MESSAGES = GWT.create(GenericMessages.class);
I usually do this in every class that uses the GenericMessages Interface, is this a nice thing to do, or should I create a MessagesSingleton that instantiates all my Messages interface and I just access it from there?
Thanks in advance.
You don't have to worry about it. The GWT compiler will replace all your GENERIC_MASSAGES inside the code.
Example:
If you have in your propert file:
applicationName=My Application
and in your java class like this:
label.setText(GENERIC_MESSAGES.applicationName());
in compilation time the gwt compiler will replace to
label.setText("My Application");
and will remove your variable.

GWT and Vaadin - variable is not a constructor stack

I have a strange error that I cannot make heads or tails of. A snippet of the error is below:
(TypeError): $wnd.EGeoXml is not a constructor stack: $jsInit([object Object],[object Object],null)
The actual lines of code is in GWT and looks like this:
private native void jsInit(JavaScriptObject map, String kmlFile) /*-{
var exml = new $wnd.EGeoXml("exml", map, kmlFile, {});
this.#com.example.client.EGeoXmlJava::ready(Lcom/google/gwt/core/client/JavaScriptObject;)(exml);
}-*/;
This code actually works when running as its own GWT project but when using this code with Vaadin, I get the constructor stack error. I'm positive the constructor exists. What I do not understand is why GWT thinks it's not a constructor? Thanks in advance.
You are calling it like new $wnd.EGeoXml(). The $wnd part looks bit weird to me. Is it necessary?
Anyway, if it is a problem only in Vaadin project, you might want check that the code resides in the right package. Remember that GWT wants the code to be in a package called .client. The server-side classes of Vaadin can be anywhere.