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?
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.
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.