2014-03-13 3 views
0

1. 예외 메시지를 팝업 창에 표시하려고합니다. 예외 메시지가 나타나지 않습니다.팝업 창 레이블이로드되지 않습니다.

2.Eg : 내가 버튼을 팝업 창 (두 번째 fxml 파일)을 클릭

3.Popup 창이 표시되고 레이블에 적절한 예외 메시지를로드하는 것입니다,하지만 라벨이로드되지 않은 (굵게 하나 ->ExceptionLabel.setText ("올바른 파일 경로를 입력하십시오")) 그것은 널 포인터 예외를 말합니다.

4. 실종 내용을 잘 모르겠습니다. FX : ID에서 선언 된 것과 동일하며 두 번째 fxml 파일에서도 주 컨트롤러를 연결합니다. 미리 감사드립니다. 내가 그것을 표시지고 "OK"핸들 버튼에 라벨을 유지하는 경우

Popup window without label

@FXML public Label ExceptionLabel; Stage PopupWindow = new Stage(); public void Buttonhandle(ActionEvent event) throws IOException { try { if(ESBOutboundFile!=null && OutputFile!=null){ String Output = SBlogpaser.Logpaser(ESBInboundFile,ESBOutboundFile,OutputFile); System.out.println(Output); }else{ Window(PopupWindow); **ExceptionLabel.setText("Please enter Proper file path");** } } catch (Exception ex) { System.out.println(ex); } } public void Window(Stage Popup) throws Exception { this.Popup=Popup; final FXMLLoader fxmlLoader = new FXMLLoader(); Parent root= fxmlLoader.load(getClass().getResource("POPUPWindow.fxml")); Scene scene1 = new Scene(root); Popup.setScene(scene1); Popup.show(); } 
.

답변

1

여기서 ExceptionLabel을 인스턴스화 할 것으로 예상되는 위치는 어디입니까?

POPUPWindow.fxml 파일의 루트에있는 fx : controller 특성을 현재 클래스로 지정한다고 가정하면이 클래스의 새 인스턴스를 만들고 해당 인스턴스에 값을 주입합니다. 현재 인스턴스의 ExceptionLabel 필드는 초기화되지 않습니다.

public void window(Stage popup) throws Exception { 
    this.popup=popup; // why? 
    final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("POPUPWindow.fxml")); 
    fxmlLoader.setController(this); 
    Parent root= fxmlLoader.load();    
    Scene scene1 = new Scene(root); 
    popup.setScene(scene1); 
    popup.show();  
} 

를하고 FX 제거 :

당신은 아마 거의 같은 현재 개체, 뭔가에 FXMLLoader의 컨트롤러를 설정하여이 작품을 만들 수 POPUPWindow.fxml에서 컨트롤러 속성을.

그러나 현재의 개체가 두 개의 다른 FXML 파일에 대한 컨트롤러로 작동하기 때문에 이것은 정말 나쁜 생각입니다. 이것은 기껏해야 혼란스럽고 상당히 합리적인 조건 하에서 이상한 결과를 낳을 것입니다. 이 팝업에 대해 다른 컨트롤러 클래스 작성하기가 훨씬 더 좋을 것이다 (...) 메소드 위의 창을 사용하여 다음

public class PopupController { 
    private final String message ; 
    @FXML 
    private Label exceptionLabel ; 

    public PopupController(String message) { 
    this.message = message ; 
    } 

    public void initialize() { 
    exceptionLabel.setText(message); 
    } 
} 

을하고, 그러나 당신이 있다면 분명히

fxmlLoader.setController(new PopupController("Please enter Proper file path")); 

와 윈도우 (..) 메소드를 재사용하면 메시지를 매개 변수로 해당 메소드에 전달할 수 있습니다.

+0

여전히 작동하지 않습니다 ....... – mani

+0

PopupController 접근 방식을 사용했는데 exceptionLabel이 여전히 null입니까? –

+0

이번에는 예외는 아니지만 메시지가 표시되지 않습니다. popupcontroller가 제대로 호출되지만 public void initialize() 메서드로 전달되지 않습니다. 수동으로 호출하면 레이블 세트 텍스트에 null 포인터 예외가 throw됩니다. – mani