2014-09-19 29 views
0

我有一個問題,遇到我想不通:東西是錯誤的,當我加載FXML文件在類的構造函數

public Attribution{ 
    FXMLLoader loader; 
    Group tree; 
    Scene scene; 
    AttributionNodeController controller; // This is the corresponding controller 
    public Attribution() { 
     try { 
      System.out.println("Attribution constructor"); 
      loader = new FXMLLoader(Attribution.class.getResource("/view/AttributionNode.fxml")); 
      tree = loader.load(); 
      controller = loader.getController(); 
      scene = new Scene(tree);      
     } catch (Exception e) { 

    } 
} 

}

而且,我步調試這個程序,

loader = new FXMLLoader(Attribution.class.getResource("/view/AttributionNode.fxml")); 

此語句運行得很好,但後來,

tree = loader.load(); 
    controller = loader.getController(); 
    scene = new Scene(tree); 

這三條語句將被刪除。

那麼,爲什麼會發生這種情況呢? 非常感謝你的提示!

回答

0

對不起,我終於搞明白了。在相應的控制器中,有些變量是不正確的,因爲我使用JavaFX Builder修改了相應的變量名稱。

相關問題