개발/Java

[Java] JavaFX 오류 해결 (Location is not set)

hojak99 2017. 4. 19. 09:11
    @Override
    public void start(Stage primaryStage) throws Exception {
        this.stage = primaryStage;
        this.stage.setTitle("title");

        // fxmlPath = new File("src/main/java/ui/view/LoginPage.fxml").toURL();

        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(getClass().getResource("view/LoginPage.fxml"));
        layout = (AnchorPane) loader.load();

        Scene scene = new Scene(layout);
        stage.setScene(scene);
        stage.show();


    }


이런 식으로 코드를 작성해서 .fxml 파일을 불려오려고 했을 때 "java.lang.IllegalStateException: Location is not set." 이라는 오류가 발생하였다.


그래서 스택오버플로우에서 찾은 오류 해결 방법은 다음과 같다.



@Override
    public void start(Stage primaryStage) throws Exception {
        this.stage = primaryStage;
        this.stage.setTitle("title");

        URL fxmlPath = new File("src/main/java/ui/view/LoginPage.fxml").toURL();

        FXMLLoader loader = new FXMLLoader();
        layout = (AnchorPane) loader.load(fxmlPath);

        Scene scene = new Scene(layout);
        stage.setScene(scene);
        stage.show();
    }


해결~

반응형