How to solve infinite recursion in java (stack overflow)?
<p>I have problem with infinite recursion. Main method will run, then if I chose 1, it will go to submenu(). But, when I choose a wrong option in submenu(), the program must be loop back to main method. </p>

<p>However, this situation can result stack overflow. </p>

<p>Do you have any ideas guys related to this problem? How could the it loop back to main method without calling the main()?</p>

<p>Thanks a lot guys.</p>

<pre><code>   public void main() {
      // variables omitted
      while (menu) {

         switch (option) {
         case 1:
            subMenu();
            break;
         }
      }

   }

   public void subMenu() {
      switch (a) {
      case 1:
      case 2:
      default:
         System.out.println("Invalid Option");
         main();
      }
   }
</code></pre>
