2010-04-03 6 views
3

Je suis en train d'exécuter la ligne suivante:problèmes de coulée avec Google Maps API

Directions.loadFromWaypoints((Waypoint[])waypoints.toArray(), opts); 

Mais je reçois:

23:41:44.595 [ERROR] [carathome] Uncaught exception escaped 
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lcom.google.gwt.maps.client.geocode.Waypoint; 
    at com.presasystems.gwt.carathome.client.widgets.MostrarLinhasPanel$1$1.onSuccess(MostrarLinhasPanel.java:72) 
    at com.presasystems.gwt.carathome.client.widgets.MostrarLinhasPanel$1$1.onSuccess(MostrarLinhasPanel.java:1) 
    at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:216) 
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287) 
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393) 
    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:157) 
    at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713) 
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165) 
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120) 
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507) 
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264) 
    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:188) 
    at sun.reflect.GeneratedMethodAccessor9.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:157) 
    at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668) 
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401) 
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222) 
    at java.lang.Thread.run(Unknown Source) 

Pourquoi? Ce casting ne devrait-il pas fonctionner? Comment puis-je le faire d'une manière élégante? Merci à l'avance

Répondre

1

Essayez

Directions.loadFromWaypoints((Waypoint[])(waypoints.toArray()), opts); 

Vous pouvez également

Waypoint[] array = new Waypoint[0]; 
array = waypoints.toArray(array); 
Directions.loadFromWaypoints(array, opts); 

Ou plus simplement

Waypoint[] array = waypoints.toArray(new Waypoint[0]); 
Directions.loadFromWaypoints(array, opts); 

Voir aussi List#toArray(T[] a).

Addendum: Au début, je pensais que votre distribution était un problème de priorité. Le paramètre générique T dans List#toArray(T[] a) élimine le besoin d'un cast explicite en s'assurant que le "type d'exécution du tableau retourné est celui du tableau spécifié." En effet, il "agit comme un pont entre les API basées sur les baies et sur les collections."

+0

Cela n'a pas fonctionné, désolé – Thiago

+0

Pouvez-vous poster un lien vers l'API? – trashgod

+0

http://gwt-google-apis.googlecode.com/svn/javadoc/maps/1.0/index.html – Thiago