2016-10-19 3 views
0

새 창을 여는 데 사용할 런처 클래스가 있습니다. 런처 주에서 서브 디렉토리에서 FXML을 부풀림

, 내가 전화 해요 :

ChatList chatList = new ChatList(communicator);

ChatList의 생성자는 호출 나는 FXML 문서 팽창하려고 방법 showChatList() : 난 그러나

private void showChatList() { 
    try { 
     FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("fxml/ChatList.fxml")); 
     Parent root = (Parent) fxmlLoader.load(); 
     Stage stage = new Stage(); 
     stage.setScene(new Scene(root)); 
     stage.show(); 
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 
} 

을 내가 fxmlLoader.load()라고 부를 곳인 java.lang.IllegalStateException: Location is not set.을 얻는다. 다음과 같이 내 프로젝트 파일 구조는 다음과 같습니다 나는 FXML 파일에 대한 절대 파일 경로에서 퍼팅 시도하지만 여전히 운이 없었습니다

project structure

.

JavaFX에서 FXML을 (여러 단계로) 부 풀리는 것의 일반적인 원리를 이해하거나 나를 만날 수있는 좋은 리소스를 알려줄 수있는 사람이 있습니까?

건배.

+0

이것이 도움이되는지 확신 할 수 없지만 새로운 FXMLLoader (getClass(). getClassLoader(). getResource (// path);)를 시도해야합니다. –

+0

그래서이 말을하는 것입니다. :'FXMLLoader fxmlLoader = 새로운 FXMLLoader (getClass(). getResour ce ("// fxml/ChatList.fxml"));'? 그것은 여전히 ​​작동하지 않습니다. –

답변

1

나는 이것이 오래된 질문이지만 누군가를 도울 수 있음을 알고 있습니다.

fxml의 모든 경로를 써야합니다. 귀하의 경우에는 은 다음과 같습니다

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/client/fxml/ChatList.fxml")); 

또 다른 예 : Youproject/src에/parentpackage/childpackage/fxmlToGet.fxml

당신이 childpackage에서 fxml을 얻고 싶은 경우에 당신은 쓸 필요가 :

FXMLLoader(getClass().getResource("/parentpackage/childpackage/fxmlToGet.fxml")); 
관련 문제