I'm getting an error message below and can't figure out why. The message is as follows:

Exception in thread "Thread-3" java.lang.StackOverflowError
        at java.awt.geom.Ellipse2D$Float.getX(Ellipse2D.java:92)
        at java.awt.geom.EllipseIterator.<init>(EllipseIterator.java:25)
        at java.awt.geom.Ellipse2D.getPathIterator(Ellipse2D.java:405)
        at java.awt.geom.Path2D$Float.<init>(Path2D.java:215)
        at java.awt.geom.Path2D$Float.<init>(Path2D.java:190)
        at sun.java2d.pipe.LoopPipe.fill(LoopPipe.java:249)
        at sun.java2d.pipe.LoopPipe.fillOval(LoopPipe.java:123)
        at sun.java2d.SunGraphics2D.fillOval(SunGraphics2D.java:2158)

I'm getting this on the specified line of the code below (explosion[i].paintSprite(g);). If I remark out the line, or do something else with the Graphics var g, I'm good. Once I place this code back in, it breaks. Does anyone know what the problem is? Doesn't make sense.

int gravity, a, v, T, L, x, y;
           explosion = new FireworksSprite[100];
           double valueA, valueB, dx, dy;
           int t;
           Random r = new Random();
           for(t = 0; t < explosion.length; t ++)
          {
               gravity = 20;
               a = r.nextInt(50);
               v = r.nextInt(50);
               //System.out.println("a = " + a);
               //System.out.println("v = " + v);
               valueA = v*Math.sin(a)*t;
               valueB = (.5)*gravity*(t*t);
               dx = (int)v*Math.cos(a)*t;
               dy = (int)valueA - valueB;
               x = (int)dx;
               y = (int)dy;
               //System.out.print("Iterating through Array" + t);
               explosion[t] = new FireworksSprite();
               explosion[t].setSpriteH(15);
               explosion[t].setSpriteW(10);
               explosion[t].setLocx(x);
               explosion[t].setLocy(y);
               explosion[t].setActive(true);
               explosion[t].setVisible(true);
               explosion[t].setVel(0, v); 
           }
               for (int i = 0; i < explosion.length; i ++)
               {
                  explosion[i].paintSprite(g);  //PROBLEM LINE IN CODE
               //System.out.println("i is: " + i);
               }
    }

You would need to post the paintSprite() method code, as that is the one making the calls into the graphics methods that are overflowing the stack.

You would need to post the paintSprite() method code, as that is the one making the calls into the graphics methods that are overflowing the stack.

Thanks Ezzaral, you helped. I was looking at the paintSprite() method in order to post it, and saw the problem; didn't realize it before now. Had simple logic error and am now good to go.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.