0

Basically an exception is being thrown and I can't find the reason. Here is what I get on the console:

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)

It is obviously from a batik lib that I use to paint SVG files, but I made sure that nothing is painted until the document is loaded, ready and showing on screen. When thrown nothing is painted.

Another interesting thing is the timing of the throwing. I am unable to find any logical patern, as sometimes it is thrown as soon as I initiate the class and sometimes it needs more then five minutes. In addition to this, as far as I tested there is no single action that calls repaint() that triggers it or rather all do.

I am new to Java and all the other exceptions had the class and row number of where they were thrown so I don't know what to do here.

Any suggestions would be greatly appreciated.

The code is enormous so I'll put just the paint method and if anything additional is needed please say so.

@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){

            }
        }
    } 

edit: There is no array in my class so i can't check any index. I think that this exception is thrown from a library I use, but it's a .jar file and I don't know how to open it or if I can.

Invader Zim
  • 796
  • 2
  • 14
  • 39
  • 1
    add a breakpoint into org.apache.batik.gvt.renderer.StrokingTextPainter.computeTextRuns and try to figure out what causes the out of bounds exception. Maybe the paintElements method would be interesting too. – wemu Oct 25 '12 at 10:30
  • 4
    I despair whenever I see something like this: `catch(NullPointerException e){}` – Stephen C Oct 25 '12 at 10:31
  • Exceptions like NullPointerException and ArrayIndexOutOfBoundsException should almost never be caught. They are so easy to check for and avoid that it is considered a programming error if they are ever thrown. – John Watts Oct 25 '12 at 10:45
  • @wemu I don't know how to do it. It is a jar file from a lib that is being used. paintElements is ok because it only paints additional stuff on the canvas. – Invader Zim Oct 25 '12 at 10:51
  • @StephanC A leftover from earlier coding. The first priority is resolving this problem, I can later throw out the unnecessary stuff. The whole try-catch branch is unnecessary as its handled with documentLoaded variable. – Invader Zim Oct 25 '12 at 10:51
  • @JohnWatts I know, but that is the problem. There is no index to begin with. If I had an array it would be the first thing I would check but I dont have it. – Invader Zim Oct 25 '12 at 10:55
  • well download the sources lib from apache: http://xmlgraphics.apache.org/batik/ add it to your IDE and then it should be easy to add a breakpoint and go up the call-tree to see where the wrong parameter comes from – wemu Oct 25 '12 at 11:23
  • In Eclipse you can set a Breakpoint on the throwning of an Excpetion. Bring yourself near to the event, activate the breakpoint, click, and wait till the code throws the exception – Jordi Laforge Oct 25 '12 at 11:45
  • @JordiLaforge I was just about to download the source code but putting it all together would take alot (cause I'm a newbie). You saved me a lot of time. Will try now. – Invader Zim Oct 25 '12 at 11:58

1 Answers1

0

It appears that the exception is thrown after a "mouse entered" event while the library is attempting to calculate something about the geometry. None of the classes in the stack trace appear to be listeners you have defined. I'm afraid I don't know anything about this library, but I suggest you go through the UI you have defined for things that aren't quite right, or even just things that you can remove and attempt to reproduce the problem. It looks like either something is wrong with the rendered geometry or the listener is getting called before it is supposed to, and depends on rendering that has not happened yet.

arcy
  • 12,845
  • 12
  • 58
  • 103
  • Sadly I can remove only things from my class because this is a part of a bigger project and the only drawable thing in the class is the class itself (it is extended with JSVGCanvas). But if I understood you correctly if I had no mouse I wouldn't have the mouse entered event and thus no exception would be thrown? [: If this is the case then this exception is irrelevant because the application would be used on a touch screen panel. I figure that it would be possible for it to be thrown but there won't be any dragging on the application, only touching some buttons, so I am good? – Invader Zim Oct 25 '12 at 12:09
  • No, because the issue arises because of a "mouse entered event"; I don't know enough about touch screen systems (and certainly not about your unnamed one) to know when that is fired. I think what is being illustrated best here is how difficult, and mostly fruitless, it is to make guesses about things without enough information. Your situation is mostly unclear; we don't know the system, we don't know what you're trying to do, we don't have any evidence of what you've tried, we don't even have enough to make decent suggestions about how to explore it. Sorry. – arcy Oct 27 '12 at 13:59