Understanding drawImage()
<p>I've been having trouble with drawing using drawImage(BufferedImage, int, int, null). I always get a NullPointerException for the drawImage line, even when I am sure that my BufferedImage input exists and is, in fact, a BufferedImage. My code is below, and I guarantee that the getTerrainAsset() method of Area will return a BufferedImage. </p>

<pre><code>import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.*;

public class CastleDefense {

   public static void main(String[] args) {
    new CastleDefense();
  }
  public CastleDefense() {
    Area area = new Area();
    JFrame frame = new JFrame("Castle Defense");
    frame.setSize(300, 500);
    Graphics g = area.getGraphics();
    g.drawImage(area.myArea[0][0].getTerrainAsset(), 10, 10, null);
    frame.setVisible(true);
    frame.add(area);
  }
 }
</code></pre>

<p>In other code I've seen that uses Graphics, there's a paintComponent(Graphics) method that contains the drawImage line and a super.paintComponent(Graphics) line, but the paintComponent(Graphics) method itself is never called in the main method. I don't understand how this works. </p>