Getting a nullpointerexception error when trying to draw to canvas
<p>I'm trying to paint essentially a checkerboard pattern to the screen by using a 2d array and painting 10x10 pixel blocks at the current coordinate based on what character is read from the array location. I think this is all the code related to the problem:</p>

<pre><code>public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2d = (Graphics2D) g;
        g.fillRect(0, 0, this.getWidth(),this.getHeight());
        for(int x = 0;x&lt;=3;x++){
            for(int y = 0;y&lt;=3;y++){
                                // NPE occurs on this line:
                if (globalmap[x][y] == '1'){g2d.fillRect(10*y, 10*x, 10,10);}
            }
        }
}
</code></pre>

<p>This is the map array:</p>

<pre><code>0000
0011
0100
0000
</code></pre>

<p>Stack trace:</p>

<pre><code>    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at com.side.side.GameEngine.paint(GameEngine.java:64)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JLayeredPane.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paintToOffscreen(Unknown Source)
        at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
        at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
        at javax.swing.RepaintManager.paint(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
        at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
        at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
        at java.awt.Container.paint(Unknown Source)
        at java.awt.Window.paint(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
       at java.awt.EventDispatchThread.run(Unknown Source)
</code></pre>

<p>Line 64:</p>

<pre><code>if (globalmap[x][y] == '1') { g2d.fillRect(10*y, 10*x, 10,10); }
</code></pre>
