+ 3
What is java.lang.StackOverFlow error?
I tried to prepare a program using Threads but unfortunately it crashes with the StackOverFlow error.I can't understand that how can I resolve this error. Please help me so that I can complete my program. The code is below:- https://code.sololearn.com/c0j3SWnXKlnc/?ref=app
4 Respuestas
+ 3
You are creating a new instance of a customer class from the sl class, and then creating a new instance of the sl class in that customer class. This is recursive, and a recursive function with no base case results in a stack overflow exception. You should only instantiate one of each class as public, then reference them to each other.
+ 3
Thanks for the suggestion.
You mean that I have to create a different public class that will run all the methods and initiate all the classes.
+ 3
That's not exactly what I meant. I suggest doing something like public sl sl1 = new sl(), then referencing only to sl1 throughout the entire program, and not using any new instances of that class anymore.
+ 1
OK Thank You very much.