开发者

JavaScript exceptions with compiled GWT code

During compilation of a GWT class I got some compiler exception. I filed a bug report for that here: http://code.google.com/p/google-web-toolkit/issues/detail?id=6623

Now I found how to make it compile anyway, by using "draftCompile". However, the generated JavaScript code doesn't work when executed.

The Java source files are available from the bug tracker, and the compiled project is here: http://clientss开发者_如何学Ch1.rbg.informatik.tu-darmstadt.de:9000/war/Gwittest.html

The error is: (Chrome) "Uncaught TypeError: Cannot read property 'testpackage_shared_ship_Level_boards' of null". In Firefox its another error.

The code works in Dev Mode (from Eclipse).

How do I work around this error? Is it related to the compilation/optimization bug? How do I work around it? If it is a bug in and of itself, I should report this too, no?

Edit: the class in question is here: https://gist.github.com/1139147


The error sounds like the compiled javascript contains code like:

null.testpackage_shared_ship_Level_boards

This would happen if the GWT optimizer believes that your variable of type "Level" which has its field "boards" read, must be null. The optimizer is usually right about that.

So, an approach is to: Compile the code into human readable javascript (-style pretty). Get the javascript error and find the line that caused it. Find the corresponding line your Java source, and trace back where the value of your variable comes from. You will likely find that the variable was not initialized.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜