This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

see anything wrong with this...

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

Joined: Oct 23, 2005
Posts: 3703
    
    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: 24183
    
  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]
 
 
subject: StackOverflowError
 
Similar Threads
Why cant i call main method from another class having main block
Collections.synchronizedMap?
Infinte loop and Recursive function
q on strings
customized constructors