JavaFX FXML 2.2中的未知异常/错误

时间:2013-12-27 16:24:56

标签: java exception nullpointerexception javafx

我正在使用 NetBeans 7.3.1 JavaFX 2.2。

我收到的错误只是'2'(不像NullPointerException等)。当我更改一些二维数组值时,则错误是其他数字。

StackTrace:

  

使用平台D:\ Java \ jdk1.7.0_25 / bin / java

从(我的项目路径).jar执行com.javafx.main.Main      

2这是我的错误。有时候是6,5等等。

file:/(my project path).jar!/<project name>/SelectionWindow.fxml

at <project name>.SelectionWindowController.attachBrandImagesAndNamesToTiles(SelectionWindowController.java:92)
  at <project name>.SelectionWindowController.initialize(SelectionWindowController.java:33)

  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2152) 
  at ..... all the trailing trace

解释这个错误以及如何解决它。

2 个答案:

答案 0 :(得分:0)

好吧,看到异常从这一行抛出:

brandNames[i][j] = new Label(DataInterface.getBrandName(i, j));

假设您的数组元素超出范围可能是合理的,如果您尝试从数组中获取元素2,则会导致它抛出OutOfBoundsException 2,但例如它只有1个元素。< / p>

如果没有完整的堆栈跟踪,很难确定。

答案 1 :(得分:0)

这很难说。堆栈跟踪显示第92行的错误,即:

brandNames[i][j] = new Label(DataInterface.getBrandName(i, j));

javafx.scene.control.Label构造函数似乎没有抛出任何异常(请参阅http://docs.oracle.com/javafx/2/api/javafx/scene/control/Label.html#Label%28java.lang.String%29)。我会说

  • 在整个内循环周围放置一个try / catch块。
  • 在catch语句中,使用反射来找出异常的类类型究竟是什么(如果你不知道怎么回发,我将为你编写代码)
  • 然后还从捕获的异常中写出消息。