2014-04-22 2 views
1

here과 비슷한 일반적인 아이디어와 비슷한 윈도우를 다른 응용 프로그램 위에 만듭니다. 저는 아직 JavaFX에 익숙하지 않고 이것을 수행하는 간단한 방법을 찾고 있습니다. 그러나 더 복잡한 형식으로 각각 자신의 .fxml 파일을 가지고 있습니다. btnNewProjectClicked가 호출 될 때까지두 개의 Windows를 동시에 엽니 다. - JavaFX

public void btnNewProjectClicked(){ 
    //! this should open the other form, but it doesn't 
    Parent root; 
    try { 
     root = FXMLLoader.load(getClass().getClassLoader().getResource("../fxml/NewProject.fxml")); 
     Scene scene = new Scene(root, 300, 250); 
     Stage stage = new Stage(); 
     stage.setTitle("It works!"); 
     stage.setScene(scene); 
     stage.show(); 

    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

모든 부모 창 잘 작동 : 이것은 내가 지금까지있는 것입니다. 오류가 발생하면 다음과 같은 오류가 발생합니다.

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: 
    java.lang.reflect.InvocationTargetException 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source) 
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown 
     Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source) 
    at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source) 
    at javafx.event.Event.fireEvent(Unknown Source) 
    at javafx.scene.Node.fireEvent(Unknown Source) 
    at javafx.scene.control.Button.fire(Unknown Source) 
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown 
     Source) 
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source) 
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source) 
    at 
com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
    at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source) 
    at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source) 
    at javafx.event.Event.fireEvent(Unknown Source) 
    at javafx.scene.Scene$MouseHandler.process(Unknown Source) 
    at javafx.scene.Scene$MouseHandler.access$1800(Unknown Source) 
    at javafx.scene.Scene.impl_processMouseEvent(Unknown Source) 
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source) 
    at com.sun.glass.ui.View.handleMouseEvent(Unknown Source) 
    at com.sun.glass.ui.View.notifyMouse(Unknown Source) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source) 
    at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.reflect.InvocationTargetException 
    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 sun.reflect.misc.Trampoline.invoke(Unknown Source) 
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at sun.reflect.misc.MethodUtil.invoke(Unknown Source) 
    ... 48 more 
Caused by: java.lang.NullPointerException: Location is required. 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.load(Unknown Source) 
    at back_end.controllers.StartScreen_Controller.btnNewProjectClicked(StartScreen_Controller.java:98) 
    ... 57 more 

이 작업을 수행하려면 무엇을 변경해야합니까? -> 호기심 많은 분들은 98 호선이 FXMLLoader 호입니다.

답변

2

는 ".."getResource(...) 제공하는 문자열에 유효하지 않습니다. 일반적으로 jar 파일 내부에서로드하는 것을 기억하십시오. (상대 경로가 정의되는 실제 개념이 없습니다.) 형식으로 경로를 입력하십시오.

getClass(). getResource ("/ path/to/fxml/NewProject.fxml");

여기서 정의하는 경로는 클래스 경로와 관련이 있습니다.

+0

이것은 효과가 있습니다. 그래서 그것을 'root = FXMLLoader.load (getClass(). getResource ("/ fxml/NewProject.fxml"))로 변경했습니다. –

1

나는 또한 같은 문제에 직면,이를 대체하기 위해 시도하십시오 :이와

getClass().getClassLoader().getResource("../fxml/NewProject.fxml") 

을 :

getClass().getResource("../fxml/NewProject.fxml") 
+0

나는 당신이 제안한 변화를 만들었고 그것은 나에게 같은 오류를주고있다. –

+0

@QuinnMcHugh 당신은 폴더 구조를 보여 주실 수 있겠습니까? – nikis

관련 문제