2014-04-20 6 views
0

정보 (lattiude, longitude)를 html webview의 Google지도에 전달하려고합니다. 문제는 응용 프로그램이 넷빈에서 시작하지 않는다는 것입니다. 그것은 반환 : 여기JavaFX에서 Javascript로 정보 전달

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')"); 

    }  

} 

그리고지도와 HTML :

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

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

다음

코드 당신은 거의 확실하게 페이지가 전에 자바 스크립트를 실행하려고

<!DOCTYPE html> 
<html> 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
    <meta charset="utf-8"> 
    <style> 
     html, body, #map-canvas { 
     height: 100%; 
     margin: 0px; 
     padding: 0px 
     } 
    </style> 
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> 
    <script> 
     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); 

    </script> 
    </head> 
    <body> 
    <div id="map-canvas"></div> 
    </body> 
</html> 
+0

스택 추적에 따르면이 문제는 OpenPilot의 29 행에 있습니다 (start 메서드의 어딘가에 있음). 그 코드를 보여줄 수 있습니까? –

답변

1

짐을 실은. 웹 엔진로드가 완료되면 스크립트를 실행할 처리기를 지정해야합니다.

@Override 
public void initialize(URL url, ResourceBundle rb) { 

    URL MapURL = getClass().getResource("map.html"); 
    WebEngine WebEngine = Map.getEngine(); 
    WebEngine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> { 
     if (newState == State.SUCCEEDED) { 
      WebEngine.executeScript("getCoordinates('40.3130432088809')"); 
     } 
    }); 
    WebEngine.load(MapURL.toExternalForm()); 

} 
+0

넷빈즈는이 줄이 잘못되었다고 말합니다 :'WebEngine.getLoadWorker(). addListener ((ov, oldState, newState) -> {'그건 : addlistener에 적합한 메소드가 없습니다' – user3203690

+0

임포트 추가 : 'import javafx.concurrent.Worker.State;'고 수정했는지 확인하십시오 –

+0

다른 문제가 있습니다 – user3203690