FXMLLoader 无法解释 fxml getTitle 方法

fxml getTitle method can't be interpreted by FXMLLoader

我的 FXML 代码有问题。 我想在初始化时获取舞台标题的字符串,但是当我尝试调用操作 stage.getTitle() 时,FXMLLoader 抛出异常。 我也尝试在其他方法中获得标题,但它只在其中一些方法中起作用。谁能告诉我那里的问题是什么?

这是初始化舞台的地方:

@FXML
private void handleModellAction(ActionEvent event) throws IOException{
    FXMLLoader load = new FXMLLoader(getClass().getResource("InEX.fxml"));
    Parent root = (Parent) load.load();
    Stage stage = new Stage();

    stage.setScene(new Scene(root));
    stage.show();

    link = (Hyperlink) event.getTarget();
    model = link.getText();

    stage.setTitle(model);
}

这是控制器中的初始化方法class:

public void getTitle(){
    System.out.println(this.stage.getTitle());
}

@Override
public void initialize(URL url, ResourceBundle rb) {
    image = new Image("images/test.png", 1500, 900, true, true);
    interieurImg.setImage(image);

    model = this.stage.getTitle();
}

这是抛出的异常:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException     
   at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)         
   at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)      
   at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)       
   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)      
   ... 52 more      

   Caused by: javafx.fxml.LoadException: file:/C:/Users/p356545/Documents/NetBeansProjects/VFAfxml3/dist/run1293777989/VFAfxml3.jar!/vfafxml3/Interieur.fxml        
   at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)   at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)        
   at ...       
   at vfafxml3.InEXController.handleInterieurAction(InEXController.java:58)     ... 62 more         

   Caused by: java.lang.NullPointerException        
   at vfafxml3.InterieurController.getTitle(InterieurController.java:49)        
   at vfafxml3.InterieurController.initialize(InterieurController.java:88)      
   at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)     ... 70 more

在 initialize-method 中获得舞台称号还为时过早。您可以在使用以下实现初始化阶段后通过任何其他方法获取它:

public String getTitle(){
    Stage stages = (Stage) anyChoosenElement.getScene().getWindow();
    String modelString = stages.getTitle();
    return modelString;
}