JavaFX 应用程序中出现意外的 ArrayIndexOutOfBoundsException,未引用任何数组

2024-01-07

我有以下代码:

 public void setContent(Importer3D importer) {
    if (DEBUG) {
        System.out.println("Initialization of Mesh's arrays");
    }
    coords = importer.getCoords();
    texCoords = importer.getTexCoords();
    faces = importer.getFaces();
    if (DEBUG) {
        System.out.println("Applying Mesh's arrays");
    }
    mesh = new TriangleMesh();
    mesh.getPoints().setAll(coords);
    mesh.getTexCoords().setAll(texCoords);
    mesh.getFaces().setAll(faces);
    if (DEBUG) {
        System.out.println("Initialization of the material");
    }
    initMaterial();
    if (DEBUG) {
        System.out.println("Setting the MeshView");
    }
    meshView.setMesh(mesh);
    meshView.setMaterial(material);
    meshView.setDrawMode(DrawMode.FILL);
    if (DEBUG) {
        System.out.println("Adding to 3D scene");
    }
    root3d.getChildren().clear();
    root3d.getChildren().add(meshView);
    if (DEBUG) {
        System.out.println("3D model is ready!");
    }
}

Imporeter3D 类部分:

  private void load(File file) {

    stlLoader = new STLLoader(file);
}

public float[] getCoords() {
    return stlLoader.getCoords();
}

public float[] getTexCoords() {
    return stlLoader.getTexCoords();
}

public int[] getFaces() {
    return stlLoader.getFaces();
}

STL加载器:

public class STLLoader{
public STLLoader(File file) {
    stlFile = new STLFile(file);
    loadManager = stlFile.loadManager;
    pointsArray = new PointsArray(stlFile);
    texCoordsArray = new TexCoordsArray();
}

public float[] getCoords() {
    return pointsArray.getPoints();
}

public float[] getTexCoords() {
    return texCoordsArray.getTexCoords();
}

public int[] getFaces() {
    return pointsArray.getFaces();
}

private STLFile stlFile;
private PointsArray pointsArray;
private TexCoordsArray texCoordsArray;
private FacesArray facesArray;
public  SimpleBooleanProperty finished = new SimpleBooleanProperty(false);
public LoadManager loadManager;}

点数组文件:

public class PointsArray {
public PointsArray(STLFile stlFile) {
    this.stlFile = stlFile;
    initPoints();
}

private void initPoints() {
    ArrayList<Double> pointsList = stlFile.getPoints();
    ArrayList<Double> uPointsList = new ArrayList<>();


    faces = new int[pointsList.size()*2];
    int n = 0;
    for (Double d : pointsList) {
        if (uPointsList.indexOf(d) == -1) {
            uPointsList.add(d);
        }
        faces[n] = uPointsList.indexOf(d);
        faces[++n] = 0;
        n++;
    }
    int i = 0;

    points = new float[uPointsList.size()];
    for (Double d : uPointsList) {
        points[i] = d.floatValue();
        i++;
    }
}

public float[] getPoints() {
    return points;
}

public  int[] getFaces() {
    return faces;
}

private float[] points;
private int[] faces;
private STLFile stlFile;
public static boolean DEBUG = true;

}

和STL文件:

    ArrayList<Double> coords = new ArrayList<>();
double temp;
private void readV(STLParser parser) {
    for (int n = 0; n < 3; n++) {
        if(!(parser.ttype==STLParser.TT_WORD && parser.sval.equals("vertex"))) {
            System.err.println("Format Error:expecting 'vertex' on line " + parser.lineno());
        } else {
            if (parser.getNumber()) {
                temp = parser.nval;
                coords.add(temp);
                if(DEBUG) {
                    System.out.println("Vertex:");
                    System.out.print("X=" + temp + " ");
                }

                if (parser.getNumber()) {
                    temp = parser.nval;
                    coords.add(temp);
                    if(DEBUG) {
                        System.out.print("Y=" + temp + " ");
                    }

                    if (parser.getNumber()) {
                        temp = parser.nval;
                        coords.add(temp);
                        if(DEBUG) {
                            System.out.println("Z=" + temp + " ");
                        }


                        readEOL(parser);
                    } else System.err.println("Format Error: expecting coordinate on line " + parser.lineno());
                } else System.err.println("Format Error: expecting coordinate on line " + parser.lineno());
            } else System.err.println("Format Error: expecting coordinate on line " + parser.lineno());
        }
        if (n < 2) {
            try {
                parser.nextToken();
            } catch (IOException e) {
                System.err.println("IO Error on line " + parser.lineno() + ": " + e.getMessage());
            }
        }
    }

}

public ArrayList<Double> getPoints() {
    return coords;
}

由于所有这些代码,我期望在 MeshView 中获得 3D 模型。但目前的结果很奇怪:一切正常并且在DEBUG我得到的模式3d model is ready! from setContent(),然后意想不到的ArrayIndexOutOfBoundsException:

File readed
Initialization of Mesh's arrays
Applying Mesh's arrays
Initialization of the material
Setting the MeshView
Adding to 3D scene
3D model is ready!
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 32252
    at com.sun.javafx.collections.ObservableFloatArrayImpl.rangeCheck(ObservableFloatArrayImpl.java:276)
    at com.sun.javafx.collections.ObservableFloatArrayImpl.get(ObservableFloatArrayImpl.java:184)
    at javafx.scene.shape.TriangleMesh.computeBounds(TriangleMesh.java:262)
    at javafx.scene.shape.MeshView.impl_computeGeomBounds(MeshView.java:151)
    at javafx.scene.Node.updateGeomBounds(Node.java:3497)
    at javafx.scene.Node.getGeomBounds(Node.java:3450)
    at javafx.scene.Node.getLocalBounds(Node.java:3432)
    at javafx.scene.Node.updateTxBounds(Node.java:3510)
    at javafx.scene.Node.getTransformedBounds(Node.java:3350)
    at javafx.scene.Node.updateBounds(Node.java:516)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.SubScene.updateBounds(SubScene.java:556)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2309)
    at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:329)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:479)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:459)
    at com.sun.javafx.tk.quantum.QuantumToolkit$13.run(QuantumToolkit.java:326)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:101)
    at java.lang.Thread.run(Thread.java:724)
Exception in thread "JavaFX Application Thread" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 32252
    at com.sun.javafx.collections.ObservableFloatArrayImpl.rangeCheck(ObservableFloatArrayImpl.java:276)
    at com.sun.javafx.collections.ObservableFloatArrayImpl.get(ObservableFloatArrayImpl.java:184)

奇怪的是,这个堆栈直到我关闭程序才停止。而且它不指向我的任何数组。这是什么?为什么会发生这种情况?


TriangleMesh 将此数组视为点坐标(x、y、z,因为它是 3D),因此数组总长度应为cords.length % 3 == 0.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JavaFX 应用程序中出现意外的 ArrayIndexOutOfBoundsException,未引用任何数组 的相关文章

随机推荐

  • Android JNI - 调用 AttachCurrentThread 而不使用 DetachCurrentThread

    我一直在阅读有关 JNI 的内容 似乎无法弄清楚如果线程启动 gt 调用 AttachCurrentThread gt 进行一些 JNI 调用 gt 线程退出会发生什么 理想情况下 我们应该在线程退出之前调用 DetachCurrentTh
  • 通过C#发送截图

    我通过该代码捕获屏幕截图来保存 Graphics Grf Bitmap Ekran new Bitmap Screen PrimaryScreen Bounds Width Screen PrimaryScreen Bounds Heigh
  • Java中的双重比较技巧

    C 允许您将两个整数比较合并为一个以进行范围检查 例如 unsigned X lt unsigned Upper 当 0 lt X lt Upper Java 语言没有无符号类型 您是否找到了一种方法来获得相同的效果 使用单个比较并且没有太
  • 如何运行 OCaml + Core 脚本?

    我正在尝试 Real World OCaml 这本书 它讨论了安装 OPAM 然后是 OCaml 和 Jane Street Core 我按照书中的说明正确加载了 utop 以便它自动加载 Core 没有 Core 我可以简单地运行通用 O
  • 坚持将 GCP 项目转移到组织

    我正在尝试将 GCP 项目 在私人帐户上 移至我管理的 GCP 组织 我知道我必须拥有正确的 IAM 权利 我相信我也这样做 我是项目中的所有者 文件夹管理员 组织管理员 项目删除者和项目移动者 我也是要搬迁项目的项目所有者和项目搬家者 但
  • “已杀:9”错误是什么意思?

    我正在编写一个程序来查找给定字符串的所有子集 然而 它会导致一个名为的错误Killed 9 class Strings object def init self string self list1 self string string de
  • Python 2.7 中枚举不可迭代

    from enum import Enum class Shake Enum order vanilla chocolate cookies mint only needed in 2 x vanilla 7 chocolate 4 coo
  • Javascript(动态)插入数组,然后将所有元素移到+1下面

    没有真正找到 Javascript 的解决方案 我需要的 我想将一个元素插入数组 但并不真正覆盖该元素 而是 动态 插入 因此插入元素 然后将其下面的所有元素移动 1 索引 例如 I have an array 14S 16S 19S I
  • Vim 配色方案更改

    我很难改变我的配色方案 我已经打开 vimrc 和 usr share vim vimrc 并添加 colorscheme desert 没事了 我注意到配色方案在这里 usr share vim vim72 colors desert v
  • Twilio 错误 - 12300 - 仅有时内容类型无效

    我有一个与数字绑定的 C NET WebApi 端点 当该号码收到短信时 它会通过 webhook 转发到我的 API 有时 并非总是 我的调试器中会出现以下错误 错误 12300 内容类型无效 Twilio 无法处理所提供 URL 的内容
  • Vue 3 中的自定义指令

    我正在尝试创建一个自定义指令来在单击元素时执行函数 我无法让它工作 我查看了自定义指令的文档 甚至直接从那里复制示例也不起作用 我正在使用单个文件模板和本地指令 这是模板
  • 不满足特征绑定“T: std::fmt::Display”

    我正在编写一个基本的二叉树结构 我想显示一个节点 Rust 似乎无法显示泛型类型 我收到此错误 error E0277 the trait bound T std fmt Display is not satisfied gt src ma
  • 在 Java 中:为什么某些 Stream 方法采用 int 而不是 byte 甚至 char?

    为什么有些方法会这样写bytes chars到流需要int代替byte char 有人告诉我如果出现以下情况int 而不是char 因为char在java中只有2个字节长度 这对于大多数已经使用的字符符号来说是可以的 但是对于某些字符符号
  • 如何根据值对 pandas 系列进行子集化?

    我有一个 pandas 系列对象 我想根据一个值对其进行子集化 例如 s pd Series 1 2 3 4 5 6 7 8 9 10 我如何对其进行子集化 以便获得仅包含大于或小于 x 值的元素的系列对象 我相信你指的是布尔索引 http
  • Outlook 365 加载项仅出现在 Outlook 2013 客户端中

    我在 Outlook 2016 中显示我的加载项时遇到问题 我将其开发为 Office365 加载项 它在 Outlook 2013 中的工作方式就像一个超级按钮 但当时我想在 Outlook 2016 中测试它 但它没有显示在 Offic
  • 错误:发送后无法设置标头。 - NodeJS 和 Express

    我有一个 NodeJS Rest API 其中有一个用户集合 此外我还进行用户短信验证 这是 POST 的控制器 id verification exports verification req res gt const id req pa
  • 在 MATLAB for Mac 中启用选项键快捷键

    自 R2009b 以来 MATLAB 通过其出色的可自定义键盘快捷键键盘快捷键首选项 http blogs mathworks com desktop 2009 09 28 configurable keyboard shortcuts h
  • 边框阴影问题

    我面临的问题是仅在多个 div 的左侧和右侧添加框阴影 我已经尝试过这个方法了 这是一 例子 http jsfiddle net Qq5tQ 我想要的 但它只适用于单个 div 并没有帮助我 我的代码有几个主要块 IE div div cl
  • 在 VS Code 中构建 SQL Server 项目

    我创建了一个 SQL Server 项目 sqlproj 在 Visual Studio 中并已将其加载到 VS Code 中 使用MS SQL 扩展 https github com microsoft vscode mssql 我可以连
  • JavaFX 应用程序中出现意外的 ArrayIndexOutOfBoundsException,未引用任何数组

    我有以下代码 public void setContent Importer3D importer if DEBUG System out println Initialization of Mesh s arrays coords imp