Sunday, May 21, 2006

Google Web Toolkit: We Got Bugs

I was bit by a few bugs myself when trying out Google's Web Toolkit. If you are unfamiliar with it, you can check out my recent post on it. In this entry I want to list the problems that I found in the hopes that it will help others, and as a reminder to myself.

Internet Explorer 7 Issue

If you try to run or debug an app with IE7 installed, you will see this error:

"Failed to load module ... .
Please see the log in the development shell for details."
[ERROR] Unable to load module entry point class


The solution is to uninstall IE7, and all will be well. Miguel from Google had this to say about it.

Yes the problem is related to IE7. When you run <your application>-shell.cmd or when you try to debug from eclipse, we will use the currently installed version of IE to host the web page. We will add support for IE7
but until we do it is better to use IE6. I apologize for the inconvenience. If we come up with a resonable work around I'll ping you with it. - Miguel Méndez

Packaging of RPC Service Interfaces

When you try out the RPC mechanism you may get some of the following errors, depending on what package you put your services interfaces in:

The import org.hanson.gwt.server cannot be resolved
MyService cannot be resolved to a type

The problem may be that the two interfaces required for RPC are not in the "client" package. There seems to be a common issue where developers are wanting to create a new Java package to store the single RPC class and two interfaces, and this is what cases the problem.

The solution is to place the two interfaces in the same package as your main application class, in the "client" package. The RPC class though can be placed in any package.

Nested Anonymous Classes Error

If you find that you can run the application in "hosted" mode, but can't compile the code to JavaScript, then this may be your problem. Here are some of the associated error messages you will see when compiling:

Analyzing permutation #1
[ERROR] Unexpected internal compiler error


The problem is that the compiler which is generating the JavaScript code is getting hung up on a reference to a variable inside of a doublely nested anonymous class.

Below is an example of code that will throw this error. The point of failure is marked with an arrow.

public class MyApplication implements EntryPoint
{

public void onModuleLoad ()
{

final Button button = new Button("Click me");
final Label label = new Label();

button.addClickListener(new ClickListener()
{
public void onClick (Widget sender)
{
MyServiceAsync svc = (MyServiceAsync) GWT.create(MyService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) svc;
endpoint.setServiceEntryPoint("/myService");

AsyncCallback callback = new AsyncCallback() {

public void onSuccess (Object result)
{
====> label.setText(result.toString());
}

public void onFailure (Throwable caught) {}
};

svc.myMethod(text.getText(), callback);
}
});

RootPanel.get("slot1").add(button);
RootPanel.get("slot2").add(label);
}
}


The problem occurs because the variable label lies within a doubly nested anonymous class, and it can't see the label declaration.

The fix is to declare label as an instance variable of the class instead of declaring it inside the method.


public class MyApplication implements EntryPoint
{

final Label label = new Label();

public void onModuleLoad ()
{
...
}
}

3 comments:

Jayesh said...

Robert, I would like to report that I also encoutered the "Analyzing permutation" compilation error, but the reason in my case was different.

I had a busy sleep statement like this:

while(!parent.isFree);

When I changed this statement to
while(true){
if(parent.isFree) break;
}

It compiled fine.
Here I didn't see the doubly nested case described in your blog.

Robert Hanson said...

> Here I didn't see the doubly nested
> case described in your blog.

I missed more than that. This was written back in May after only a week after GWT was releases. There is a new release coming out in a couple of weeks which will address some of them, but my guess is that it will be a while before it is hard to find bugs.

Anonymous said...
This comment has been removed by a blog administrator.