Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What causes a java.lang.StackOverflowError

What can cause a java.lang.StackOverflowError? The stack printout that I get is not very deep at all (only 5 methods).

like image 280
Ivan Avatar asked Jul 07 '10 18:07

Ivan


1 Answers

Check for any recusive calls for methods. Mainly it is caused when there is recursive call for a method. A simple example is

public static void main(String... args) {     Main main = new Main();      main.testMethod(1); }  public void testMethod(int i) {     testMethod(i);      System.out.println(i); } 

Here the System.out.println(i); will be repeatedly pushed to stack when the testMethod is called.

like image 95
Srinath Thota Avatar answered Sep 19 '22 20:09

Srinath Thota