当前位置: 首页 > article >正文

JavaF

JavaFx在执行以下代码后

private void updateValues(IntegerProperty[][] items, int cols, int[][] newValues) {
    IntStream.range(0, rows).parallel().forEach(row -> {
       for (int col = 0; col < cols; col++) {
           items[row][col].setValue(newValues[row][col] / 100);
       }
    });
}

 会有以下报错

Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 7436 at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266) at java.base/java.util.Objects.checkIndex(Objects.java:359) at java.base/java.util.ArrayList.get(ArrayList.java:427) at javafx.graphics/javafx.scene.Parent.updateCachedBounds(Parent.java:1704) at javafx.graphics/javafx.scene.Parent.recomputeBounds(Parent.java:1648) at javafx.graphics/javafx.scene.Parent.doComputeGeomBounds(Parent.java:1501) at javafx.graphics/javafx.scene.Parent$1.doComputeGeomBounds(Parent.java:115) at javafx.graphics/com.sun.javafx.scene.ParentHelper.computeGeomBoundsImpl(ParentHelper.java:84) at javafx.graphics/com.sun.javafx.scene.NodeHelper.computeGeomBounds(NodeHelper.java:116) at javafx.graphics/javafx.scene.Node.updateGeomBounds(Node.java:3813)

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot read field "boundsChanged" because "<local11>" is null
    at javafx.graphics/javafx.scene.Parent.updateCachedBounds(Parent.java:1705)
    at javafx.graphics/javafx.scene.Parent.recomputeBounds(Parent.java:1648)
    at javafx.graphics/javafx.scene.Parent.doComputeGeomBounds(Parent.java:1501)
    at javafx.graphics/javafx.scene.Parent$1.doComputeGeomBounds(Parent.java:115)
    at javafx.graphics/com.sun.javafx.scene.ParentHelper.computeGeomBoundsImpl(ParentHelper.java:84)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.computeGeomBounds(NodeHelper.java:116)
    at javafx.graphics/javafx.scene.Node.updateGeomBounds(Node.java:3813)
    at javafx.graphics/javafx.scene.Node.getGeomBounds(Node.java:3775)
    at javafx.graphics/javafx.scene.Node.getLocalBounds(Node.java:3723)
    at javafx.graphics/javafx.scene.Node.updateTxBounds(Node.java:3877)
    at javafx.graphics/javafx.scene.Node.getTransformedBounds(Node.java:3669)
    at javafx.graphics/javafx.scene.Node.updateBounds(Node.java:771)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1835)
    at javafx.graphics/javafx.scene.SubScene.updateBounds(SubScene.java:710)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1833)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1833)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1833)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1833)

 IntegerProperty[][] items 是Box的高度绑定的数组,执行本方法后,Box会自动更新高度,然后代码也是在UI线程中执行的,报错中也看不到任何自定义代码

问题就出在parallel方法上,parallel 是把流转换成一个并行流,本意是为了提升速度的,但用在此处就不合适了,改成普通的循环就好了

    IntStream.range(0, rows).forEach(row -> {
       for (int col = 0; col < cols; col++) {
           items[row][col].setValue(newValues[row][col] / 100);
       }
    });


http://www.kler.cn/a/595017.html

相关文章:

  • 从入门到进阶:Python数据可视化实战技巧
  • 【嵌入式】C语言中malloc()和calloc()的区别
  • 指针与引用的深度解析 (408数据结构入门)
  • C++20 中 `constexpr` 的强大扩展:算法、工具与复数库的变革
  • C++从入门到实战(五)类和对象(第一部分)为什么有类,及怎么使用类,类域概念详解(附带图谱等更好对比理解)
  • C++标准库新部件:解锁编程新姿势
  • 企业内部 Hugging Face NLP 解决方案及示例
  • 【QT5 多线程示例】互斥锁
  • 【2025考研数学真题】1987~2025数一/二/三全套真题+详细答案(无水印)
  • 期刊分区表2025年名单下载(经济学、管理学)
  • Chapter 8 Charge Pump
  • Windows平台编译webrtc
  • Flume实战:Kafka Channel的使用配置场景
  • hive 数据简介
  • Spring框架部分知识
  • 在Selenium 中更改 User-Agent 的步骤与最佳实践
  • Web-Machine-N7靶机实战攻略
  • IP地址结构体与字符串转换函数详解
  • Nginx的HTTPS配置
  • 面向医药仓储场景下的药品分拣控制策略方法 研究(大纲)