I created an array of buttons in java containing 9 buttons like this
JButton []button = new JButton[9];
When I try to access any of them later like
body.add(button[0]); or
body.add(button[1]);
it return the following error
Exception in thread "main" java.lang.NullPointerException at
java.awt.Container.addImpl(Container.java:1095) at
java.awt.Container.add(Container.java:415) at
Tic_Tac_Main.main(Tic_Tac_Main.java:105)
BUILD SUCCESSFUL (total time: 4 seconds)
Note: body is a panel in which I'm adding button But it also end with a message BUILD SUCCESSFUL.
What is wrong in the code?