0

基本上是抛出异常,我找不到原因。这是我在控制台上得到的:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
    at org.apache.batik.gvt.renderer.StrokingTextPainter.computeTextRuns(Unknown Source)
    at org.apache.batik.gvt.renderer.StrokingTextPainter.getTextRuns(Unknown Source)
    at org.apache.batik.gvt.renderer.StrokingTextPainter.getOutline(Unknown Source)
    at org.apache.batik.gvt.renderer.BasicTextPainter.getGeometryBounds(Unknown Source)
    at org.apache.batik.gvt.TextNode.getGeometryBounds(Unknown Source)
    at org.apache.batik.gvt.TextNode.getSensitiveBounds(Unknown Source)
    at org.apache.batik.gvt.AbstractGraphicsNode.getTransformedSensitiveBounds(Unknown Source)
    at org.apache.batik.gvt.CompositeGraphicsNode.getSensitiveBounds(Unknown Source)
    at org.apache.batik.gvt.CompositeGraphicsNode.getTransformedSensitiveBounds(Unknown Source)
    at org.apache.batik.gvt.CompositeGraphicsNode.getSensitiveBounds(Unknown Source)
    at org.apache.batik.gvt.CompositeGraphicsNode.getTransformedSensitiveBounds(Unknown Source)
    at org.apache.batik.gvt.CompositeGraphicsNode.getSensitiveBounds(Unknown Source)
    at org.apache.batik.gvt.CompositeGraphicsNode.getTransformedSensitiveBounds(Unknown Source)
    at org.apache.batik.gvt.CompositeGraphicsNode.getSensitiveBounds(Unknown Source)
    at org.apache.batik.gvt.CompositeGraphicsNode.nodeHitAt(Unknown Source)
    at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.dispatchMouseEvent(Unknown Source)
    at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.dispatchEvent(Unknown Source)
    at org.apache.batik.gvt.event.AWTEventDispatcher.dispatchEvent(Unknown Source)
    at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.mouseEntered(Unknown Source)
    at org.apache.batik.swing.gvt.AbstractJGVTComponent$Listener.dispatchMouseEntered(Unknown Source)
    at org.apache.batik.swing.svg.AbstractJSVGComponent$SVGListener.dispatchMouseEntered(Unknown Source)
    at org.apache.batik.swing.gvt.AbstractJGVTComponent$Listener.mouseEntered(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseEntered(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseEntered(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.trackMouseEnterExit(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$400(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

它显然来自我用来绘制 SVG 文件的蜡染库,但我确保在文件加载、准备好并在屏幕上显示之前没有绘制任何内容。抛出时没有任何东西被绘制。

另一个有趣的事情是投掷的时机。我找不到任何合乎逻辑的模式,因为有时它会在我开始上课时立即抛出,有时需要超过五分钟。除此之外,据我测试,没有一个单独的动作调用 repaint() 来触发它,或者更确切地说是所有动作。

我是 Java 新手,所有其他异常都有抛出它们的类和行号,所以我不知道该怎么做。

任何建议将不胜感激。

代码是巨大的,所以我会只放paint方法,如果需要任何额外的东西,请说出来。

@Override
    public void paint(Graphics g) {
        if(documentLoaded && showingOnScreen){
            try{
                rad = (int)(radInit+zoom*faktorRad); //max rad = 20
                super.paint(g);


                Graphics2D g2d = (Graphics2D) g;
                paintElements(g2d);

            }
            catch(NullPointerException nulle){

            }
        }
    } 

编辑:我的班级没有数组,所以我无法检查任何索引。我认为这个异常是从我使用的库中抛出的,但它是一个 .jar 文件,我不知道如何打开它或者我是否可以打开它。

4

2 回答 2

0
java.lang.ArrayIndexOutOfBoundsException 

只有在使用非法索引访问数组时才会引发此异常。索引为负数或大于或等于数组的大小。ArrayIndexOutOfBoundsException
所以这意味着在你的程序中你以错误的方式使用数组。

于 2012-10-25T10:41:09.673 回答
0

似乎在库尝试计算有关几何的某些内容时,在“鼠标输入”事件之后引发了异常。堆栈跟踪中的所有类似乎都不是您定义的侦听器。恐怕我对这个库一无所知,但我建议您查看您为不太正确的内容定义的 UI,甚至只是您可以删除并尝试重现问题的内容。看起来渲染的几何图形有问题,或者侦听器在它应该被调用之前被调用,并且取决于尚未发生的渲染。

于 2012-10-25T11:41:18.940 回答