Exception in thread "AWT-EventQueue-0" help in Java
<p>I keep on getting these errors and I cant figure out why. I know it has something to do with the buttons but I don't know how to fix them.</p>

<pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at java.awt.Container.addImpl(Container.java:1090)
    at java.awt.Container.add(Container.java:410)
    at LightsChasingSolver.&lt;init&gt;(LightsChasingSolver.java:45)
    at LightsChasingUI$2.actionPerformed(LightsChasingUI.java:153)
</code></pre>

<p>Here is my code</p>

<pre><code>final JFrame frame2 = new JFrame("Lights Chasing Solver");
GridLayout gridLay = new GridLayout(2,1);
GridLayout grid = new GridLayout(5,5);
JPanel mainPanel = new JPanel(grid);        
JPanel legendPanel = new JPanel();

final JButton[][] sht = new JButton[5][5];

for(i=0;i&lt;5;i++){
    for(j=0;j&lt;5; j++) mainPanel.add(sht[i][j]);
}
</code></pre>
