Monday, March 30, 2009

JavascriptException with Gwt Maps 1.0.3 (using GWT 1.5.3)

I had a google MapWidget that has several marker overlays. When run
in hosted mode, these markers can be seen. However, once compiled into
Javascript, the following error is thrown in Firefox:

Error: [Exception... "'com.google.gwt.core.client.JavaScriptException:
(TypeError): a is null
fileName: http://maps.google.com/intl/en_ALL/mapfiles/150c/maps2.api/main.js
lineNumber: 532
stack: (null,"C:\\myIcon.png",[object Object])@http://maps.google.com/
intl/en_ALL/mapfiles/150c/maps2.api/main.js:532
("C:\\mtIcon.png")@http://maps.google.com/intl/en_ALL/mapfiles/150c/
maps2.api/main.js:1262
l2([object Object])@http://localhost:8080/MyProject/
ACADCA4DA4C0B465E1EA03342F4CF5CC.cache.html:726
C1([object Object],[object Object])@http://localhost:8080/MyProject/
ACADCA4DA4C0B465E1EA03342F4CF5CC.cache.html:710
mx([object Object],[object Object])@http://localhost:8080/MyProject/
ACADCA4DA4C0B465E1EA03342F4CF5CC.cache.html:154
px([object Object])@http://localhost:8080/MyProject/
ACADCA4DA4C0B465E1EA03342F4CF5CC.cache.html:156
([object Event])@http://localhost:8080/MyProject/
ACADCA4DA4C0B465E1EA03342F4CF5CC.cache.html:204
' when calling method: [nsIDOMEventListener::handleEvent]" nsresult:
"0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: ""
data: no]

Hence, in both Firefox and IE, I couldn't seem to see the markers.

The reason for this is my use of absolute paths rather than relative paths. Ensure that the marker's icon is not on an external absolute URL. The markers I was using used an icon from C:\MyIcon.png. When this is deployed as a war file in Firefox and IE, the marker's icon src was null as it could not point to that URL in web mode. Solution: Ensure that the icon is
in the 'public' folder in your project. Eg. My images are in the 'public/images' folder and hence the icon's url is:
Icon icon = Icon.newInstance("images/MyIcon.png");

This will be visible in webmode when deployed using a war file.

No comments:

Post a Comment

Thank you for your comment.