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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sequence ADT Throwing StackOverflowError" Watch "Sequence ADT Throwing StackOverflowError" New topic
Author

Sequence ADT Throwing StackOverflowError

Jess Brantley
Greenhorn

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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
Greenhorn

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.


For DoubleArraySeq.java:318



This is for DoubleArraySeq.java:345



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
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: Sequence ADT Throwing StackOverflowError
 
Similar Threads
StringBuffer
StringBuffer
need help with java
AddAfter method
Filling Array