• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sequence ADT Throwing StackOverflowError

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Brantley
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.





 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic