title: I am trying to create a 10X10 grid of JButtons. I have tried using a 2D array to instantiate the buttons but I get a NullPointerException error
body: <blockquote>
    <p>As I am working in NetBeans all components have been auto generated and initialised. the JButton array has been declared as JButton [][] btnArr in the class; </p>
  </blockquote>
  
  <pre><code>private void createButtons() {
      btnArr = new JButton[10][10];
  
      for (int i = 0; i &lt; 10; i++)
          for (int j = 0; j &lt; 10; j++)
          {
              btnArr[i][j] = new JButton();
              pnlButtons.add(btnArr[i][j]); //Error on this line
              btnArr[i][j].setVisible(true);
              btnArr[i][j].setBounds(i * 30, j * 30, 30, 30);
              btnArr[i][j].setActionCommand("" + i + j);
          }
  }
  </code></pre>