2013-07-22 51 views
0

我創建一個自定義圖標作爲標記在地圖上使用,並間歇性,但往往這樣的功能:GWT地圖Icon.NewInstance間歇性地引發異常

private Icon createIcon(String Url) { 
    Icon icon = Icon.newInstance(Url); //<-- This line throws exception   
    icon.setIconSize(Size.newInstance(30, 30)); 
    icon.setIconAnchor(Point.newInstance(6, 20)); 
    icon.setInfoWindowAnchor(Point.newInstance(14, 4)); 
    return icon; 
} 

拋出此異常:

11:05:55.076 [ERROR] [simplemap] Uncaught exception escaped 

com.google.gwt.core.client.JavaScriptException: (TypeError) @com.google.gwt.core.client.impl.Impl::apply(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)([JavaScript object(311), JavaScript object(310), JavaScript object(333)]): undefined is not a function 
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249) 
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) 
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571) 
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279) 
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) 
at com.google.gwt.core.client.impl.Impl.apply(Impl.java) 
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) 
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) 
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293) 
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547) 
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364) 
at java.lang.Thread.run(Unknown Source) 

有沒有人有任何見解,爲什麼發生這種情況,我可以做些什麼來解決這種行爲?

回答

0

這最終成爲併發問題,當圖標嘗試生成時地圖未完成加載。當我移動一些代碼時,它只在Maps異步加載完成後才運行,這個問題就消失了。