I have an ArrayList of 9 JButtons, I'm looping on it ti identify every time which buttons are not played yet, but it returns the exception as Exception in thread "Thread-1" java.lang.NullPointerException
JButton buttons[] = { btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9 };
ArrayList<JButton> vide = new ArrayList<JButton>();
t = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            count++;
            for (int i = 0; i < buttons.length; i++) {
                if (!buttons[i].getText().equals("X")
                        && !buttons[i].getText().equals("O"))
                    vide.add(buttons[i]);
            }
            count++;
            Random btn = new Random();
            vide.get(btn.nextInt(vide.size())).setText("O");
            Thread.currentThread().interrupt();
        }
    });
the problem is on the loop, I'm implementing tic tac toe game of one user with a machine, this loop is to identify which buttons could be played with the machine by thread.
 
    