JavaFX ClassCastException:无法将BoxBounds强制转换为RectBounds

时间:2019-07-20 11:40:59

标签: javafx fxml classcastexception gridpane

我有一个JavaFX应用程序,它基于fxml文件创建所有UI。该应用程序抛出(但不可重现),但是时不时地抛出以下异常

java.lang.ClassCastException: com.sun.javafx.geom.BoxBounds cannot be cast to com.sun.javafx.geom.RectBounds
    at com.sun.javafx.sg.prism.NGNode.applyTransform(NGNode.java:2465)
    at com.sun.javafx.sg.prism.NGNode.accumulateGroupDirtyRegion(NGNode.java:1207)
    at com.sun.javafx.sg.prism.NGNode.accumulateDirtyRegions(NGNode.java:1022)
    at com.sun.javafx.sg.prism.NGNode.accumulateGroupDirtyRegion(NGNode.java:1189)
    at com.sun.javafx.sg.prism.NGNode.accumulateDirtyRegions(NGNode.java:1022)
    at com.sun.javafx.sg.prism.NGNode.accumulateGroupDirtyRegion(NGNode.java:1189)
    at com.sun.javafx.sg.prism.NGNode.accumulateDirtyRegions(NGNode.java:1022)
    at com.sun.javafx.sg.prism.NGNode.accumulateGroupDirtyRegion(NGNode.java:1189)
    at com.sun.javafx.sg.prism.NGNode.accumulateDirtyRegions(NGNode.java:1022)
    at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:246)
    at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:91)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
    at java.lang.Thread.run(Thread.java:748)

有一段时间我忽略了该异常,因为它似乎不会损害UI或功能。但是目前,我在调试SQL语句和记录器消息时遇到了另一个难题,而这种频繁的ClassCastException确实令人讨厌。

我正在使用Java 1.8.0_211。所以是最新版本8,其中包含JavaFX。我以为会有更多人遇到这个问题,但是我在堆栈溢出这里看不到吗?

麻烦的是,异常堆栈跟踪不指示在我的代码中何处触发了-我猜是因为FXML的分离了?我没有任何确凿的证据,但是我正在使用很多GridPanes,例如

<GridPane fx:id="pane" styleClass="pane" stylesheets="@../stylesheets/PerformanceBeacon.css" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.agiletunes.productmanager.controllers.PerformanceBeaconCtrl">
   <children>
     ...
   </children>
   <columnConstraints>
      <ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="170.0" />
      <ColumnConstraints minWidth="10.0" />
      <ColumnConstraints minWidth="10.0" />
   </columnConstraints>
   <rowConstraints>
      <RowConstraints />
   </rowConstraints>
</GridPane>

所以我相信FXML中的GridPane或我的使用方式有问题。

在查看发行说明时,我看不到它在较新的Java发行版中已得到修复。

那么如何摆脱这种异常?

谢谢。

0 个答案:

没有答案