my dog learned polymorphism
The moose likes Java in General and the fly likes Sequence ADT Throwing StackOverflowError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sequence ADT Throwing StackOverflowError" Watch "Sequence ADT Throwing StackOverflowError" New topic

Sequence ADT Throwing StackOverflowError

Jess Brantley

Joined: Oct 18, 2010
Posts: 2
Hello everyone. My name is Jessica, I'm relatively new to this, but I like to think I know the basics.

Here's the code for the DoubleArraySeq class.

Now, this part compiles just fine. There's probably still a good bit wrong, but it compiles, darnit.

Here's the Main method that actually implements the class. This is where I get my StackOverflowError.

Any insight would be very greatly appreciated.

Thank you for your time,
Jessica the n00b.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

There's a lot of code there. Instead of poring through it looking for possibilities, it would be much easier to just look at the stack trace, which should point out exactly where the problem is.

If you can't figure out what it's telling you, no problem, just post it here and ask about it.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

The catenation() method calls itself with the same parameters; that nested call will call the same method again, which will call it again, which will call it again.... until your machine stack overflows. I'm not sure whether you simply forgot to implement this method, or have an implementation in mind here which simply isn't working (do you mean to call, for example, addAll() instead?) but this method is definitely your problem. The stack trace should reflect this.

[Jess in Action][AskingGoodQuestions]
Jess Brantley

Joined: Oct 18, 2010
Posts: 2
Ernest: Those aren't the lines of code I was directed to, but maybe it still has something to do with it. I'll keep looking.

Paul: Here's exactly what I see.

Only a LOT more.

Here's what's around and on those lines.


This is for

This is making more sense to me. These are the segments I had the most trouble with, so it's more than likely I've made a few mistakes. Urg. I'm gonna look over some books and tutorials.

Thank you both very much for your help.

Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

Apart from isCurrent() and getCurrent() always calling the other one, there is another mistake. catenation calls itself without modifying the arguments. Calling this method will also lead to a StackOverflowError.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Sequence ADT Throwing StackOverflowError
It's not a secret anymore!