aspose file tools*
The moose likes Beginning Java and the fly likes StackOverflowError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StackOverflowError" Watch "StackOverflowError" New topic
Author

StackOverflowError

Matthew Gates
Greenhorn

Joined: Nov 11, 2005
Posts: 3
I have a program that I am writing that allows me to enter and display data for a group of sales representatives. The program compiles, but when I attempt to enter the name of a representative, I receive a StackOverflowError. What could be causing this?
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

Please post some sample code.

Wild guess is that you have an infinite loop.


My Blog: Down Home Country Coding with Scott Selikoff
Matthew Gates
Greenhorn

Joined: Nov 11, 2005
Posts: 3


[ EJFH: Added code tags to preserve formatting. ]
[ November 11, 2005: Message edited by: Ernest Friedman-Hill ]
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

see anything wrong with this...

[ November 11, 2005: Message edited by: Scott Selikoff ]
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

BTW, as a suggestion for debugging, I just started up Eclipse, created the class from your posted code, added a breakpoint before it asked for the representative name, then started the program in debugging mode...

after that finding where the infinite loop was trivial.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Both these routines call themselves, passing their same arguments to the new call:



When findRep(String) calls findRep(String), that second call will call findRep(String) which will call findRep(String)... eventually, the JVM will run out of stack space to keep track of all those calls that haven't returned yet, and you'll get a StackOverflowException.

Both versions of findRep need to be implemented in terms of the ArrayList, not in terms of recursive calls.



[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StackOverflowError