title: Passing info from JavaFX to Javascript
body: <p>I'm trying to passing information(lattiude, longitude) to a google map in html webview. The problem is that the application don't start in netbeans. It returns that:</p>
  
  <blockquote>
    <p>Executing
    C:\Users\Carlos\Documents\NetBeansProjects\OpenPilot\dist\run1883323097\OpenPilot.jar
    using platform C:\Program Files\Java\jdk1.8.0_05\jre/bin/java
    Exception in Application start method
    java.lang.reflect.InvocationTargetException   at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)     at
    com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:367)
      at
    com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:305)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)     at
    sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
    Caused by: java.lang.RuntimeException: Exception in Application start
    method    at
    com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:894)
      at
    com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
      at
    com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158)
      at java.lang.Thread.run(Thread.java:745) Caused by:
    javafx.fxml.LoadException:  unknown path</p>
    
    <p>at
    javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2617)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2595)    at
    javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)     at
    openpilot.OpenPilot.start(OpenPilot.java:29)  at
    com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
      at
    com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
      at
    com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
      at
    com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
      at java.security.AccessController.doPrivileged(Native Method)   at
    com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
      at
    com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)  at
    com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
      at
    com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
      ... 1 more Caused by: netscape.javascript.JSException: TypeError:
    'undefined' is not a function     at
    com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:128)   at
    com.sun.webkit.WebPage.twkExecuteScript(Native Method)    at
    com.sun.webkit.WebPage.executeScript(WebPage.java:1410)   at
    javafx.scene.web.WebEngine.executeScript(WebEngine.java:934)  at
    openpilot.FXMLDocumentController.initialize(FXMLDocumentController.java:74)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)    ... 13 more
    Exception running application openpilot.OpenPilot Java Result: 1</p>
  </blockquote>
  
  <p>Here the code:</p>
  
  <pre><code>public class FXMLDocumentController implements Initializable {
  
      @FXML public WebView Map;
  
  
  
  
  
      @Override
      public void initialize(URL url, ResourceBundle rb) {
  
          URL MapURL = getClass().getResource("map.html");
          WebEngine WebEngine = Map.getEngine();
          WebEngine.load(MapURL.toExternalForm());
          String test = "40.3130432088809";
         WebEngine.executeScript("getCoordinates('40.3130432088809')");
  
      }    
  
  }
  </code></pre>
  
  <p>And here the html with the map:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no"&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;style&gt;
        html, body, #map-canvas {
          height: 100%;
          margin: 0px;
          padding: 0px
        }
      &lt;/style&gt;
      &lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"&gt;&lt;/script&gt;
      &lt;script&gt;
          var latitude;
          var longitude;
          function getCoordinates(latitude){
    this.latitude = latitude;
  
  }
          var map;
          function initialize() {
              var mapOptions = {
                  zoom: 8,
                  center: new google.maps.LatLng(latitude, -2.900390625)
              };
          map = new google.maps.Map(document.getElementById('map-canvas'),
          mapOptions);
  
          google.maps.event.addListener(map, 'click', function(event) {
     placeMarker(event.latLng);
  });
  
  
  }
  function placeMarker(location) {
      var marker = new google.maps.Marker({
          position: location, 
          map: map
      });
  
      google.maps.event.addListener(marker, 'rightclick', function() {
                      deleteMarker(marker);
                  });
  
  }
  
  function deleteMarker(marker) {
                  marker.setMap(null); 
              }
  google.maps.event.addDomListener(window, 'load', initialize);
  
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="map-canvas"&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>