当我在类构造函数中加载fxml文件时出错了

时间:2014-09-19 21:23:24

标签: javafx

我遇到一个我无法弄清楚的问题:

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);

这三个陈述将被搁置。

那么,为什么会这样呢? 非常感谢任何人的提示!

1 个答案:

答案 0 :(得分:0)

对不起,我终于搞清楚了。在相应的控制器中,有些变量不正确,因为我用JavaFX Builder修改了相应的变量名。