RandomMove Method Tic Tac Toe Not Functional <p>I am working on creating a tic tac toe game that allows the user to play against a computer. When the user selects a button on the board, the AI will detect if there is a possible three combo. If there is no threat detected, than the computer will pick a spot randomly on the board to move.</p> <p>However, my problem is when I make a certain move, the computer sometimes places a move and sometimes get skipped. I was wondering how to fix this, my <code>randomMove()</code> method is displayed below.</p> <p>Would this situation call for a recursive method (my teacher briefly told me this might be necessary) or otherwise? If it is recursive, can you explain it? Thanks for any help!</p> <pre><code>public void RandomMove() { Random x = new Random(); int y = 1 + x.nextInt(9); if (buttons[y].getText().equals("O") || buttons[y].getText().equals("X")) { RandomMove(); } else { buttons[y].setText("O"); buttons[y].setEnabled(false); } } </code></pre> <p>More specifically I get this error sometimes:</p> <blockquote> <p>Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError</p> </blockquote>