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 ()
{
...
}
}

5 comments:

robertlight said...

I'm getting a particulary weird error when using gwt-widgets-0.0.4.jar file:

Analyzing source in module 'com.assist.gwt.cb.CB'
[ERROR] Errors in '/raid1/light/IdeaProjects/assist/cb/src/com/assist/gwt/cb/client/CB.java'
[ERROR] Line 9: The import org cannot be resolved
[ERROR] Line 57: Location cannot be resolved to a type
[ERROR] Line 57: WindowUtils cannot be resolved
[ERROR] Errors in '/raid1/light/IdeaProjects/assist/cb/src/com/assist/gwt/cb/client/DrawingTool.java'
[ERROR] Line 5: The import org cannot be resolved
[ERROR] Line 15: Color cannot be resolved to a type
[ERROR] Line 15: Color cannot be resolved
[ERROR] Line 16: Color cannot be resolved to a type
[ERROR] Line 16: Color cannot be resolved
[ERROR] Line 19: Color cannot be resolved to a type
[ERROR] Line 19: lineColor cannot be resolved
[ERROR] Line 20: Color cannot be resolved to a type
[ERROR] Line 20: fillColor cannot be resolved
[ERROR] Errors in '/raid1/light/IdeaProjects/assist/cb/src/com/assist/gwt/cb/client/RectangleTool.java'
[ERROR] Line 5: The import org cannot be resolved
Finding entry point classes
[ERROR] Unable to find type 'com.assist.gwt.cb.client.CB'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
[ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly


I have gwt-widgets-0.0.4.jar on my classpath. CB-compile is:

#!/bin/sh
APPDIR=`dirname $0`;
java -cp "$APPDIR/src:$APPDIR/lib/gwt-widgets-0.0.4.jar:/raid1/light/gwt-linux-1.0.21/gwt-user.jar:/raid1/light/gwt-linux-1.0.21/gwt-dev-linux.jar" com.google.gwt.dev.GWTCompiler -out "$APPDIR/www" "$@" com.assist.gwt.cb.CB;

Any help would be much appreciated.
It doesn't work any better if I unzip your jar file and put all the java source code below the 'src' directory ('org' being a sibling to 'com')...

Please send me mail at robert_light@verizon.net if you know of anything I'm screwing up.

thank you.

- Bob

robertlight said...

An additional hint.... it appears that I'm getting the error:

The import com.assist.gwt.cb.Foo cannot be resolved

for any class that is not in my 'project root package: com.assist.gwt.cb.client' cannot be imported. Tried to import com.assist.gwt.cb.Foo and it failed.

- Bob

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.

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