StackOverflowError w ArrayList

0

witam
napisałem programik w java który zajmuje się przesuwaniem obiektów rysowanych na JPanelu, rysuje i przesuwa on pojedyncze figury geometryczne, ale wykrzacza się przy dodawaniu figur do ArrayList co niestety jest dla mnie obowiązkowe w tym zadaniu:

Let CompoundFigure inherit Figure. Compound figure contains other figures which are stored in an ArrayList. CompoundFigure has the method public void add(Figure f), which adds a new Figure object to the compound figure. Compound figures do not have their own position, and it is not important what values are assigned to x and y coordinates. Compound figures draw themselves by asking their parts to draw themselves; the same thing happens when a compound figure moves. This means that the inherited method move has to be overwritten!

czy można prosić o jakieś sugestie?

https://4programmers.net/Pastebin/9388
Exception in thread "main" java.lang.StackOverflowError 62 linia w pastebin

1

W linii #62 ( a mówiąc bardziej szczegółowo w metodzie public void add(Figure figure) nie ma słowa o tablicy. Dlaczego jest ten wyjątek? Ponieważ w tej metodzie wywołujesz... tę samą metodę. Zamiast this.add(figure); powinno być pewnie coś ala figures.add(figure);

0

dziękuję to o to chodziło, widzę że muszę sobie trochę odpocząć, skoro robię takie błędy

1 użytkowników online, w tym zalogowanych: 0, gości: 1