title: Java getGraphics() returning null
body: <p>I'm starting to learn to create Games in Java, and one of the methods I'm using includes BufferedImage. This is the error I get: </p>
  
  <pre><code>"Exception in thread "main" java.lang.NullPointerException
       at tm.Game.init(Game.java:48)
       at tm.Game.&lt;init&gt;(Game.java:54)"
  </code></pre>
  
  <p>From this code:</p>
  
  <pre><code>package tm;
  
  import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.image.BufferedImage;
  
  import javax.swing.JPanel;
  
  @SuppressWarnings("serial")
  public class Game extends JPanel implements Runnable {
      private Settings Settings;
  
      private Thread t;
      private BufferedImage offscreenImage;
      private Graphics offscr;
  
      public void run() {
          while(true) {
              repaint();
  
              try {
                  Thread.sleep(1000/30);
              } catch (InterruptedException e) { }
          }
      }
  
      public void paint(Graphics g) {
          offscr.setColor(Color.blue);
          offscr.fillRect(0, 0, Settings.GAME_WIDTH, Settings.GAME_HEIGHT);
  
          offscr.setColor(Color.white);
          offscr.drawString("Lolz", 10, 10);
  
          g.drawImage(offscreenImage, 0, 0, this);
      }
  
      public void update(Graphics g) {
          paint(g);
      }
  
      public void init() {
          t = new Thread(this);
          t.start();
  
          offscreenImage = (BufferedImage) createImage(Settings.GAME_WIDTH, Settings.GAME_HEIGHT);
          offscr = offscreenImage.getGraphics();
      }
  
      public Game() {
          Settings = new Settings();
  
          init();
      }
  
  }
  </code></pre>
  
  <p>Settings Class:</p>
  
  <pre><code>package tm;
  
  public class Settings {
  
      public final int GAME_WIDTH = 500;
      public final int GAME_HEIGHT = 500;
  
  }
  </code></pre>
  
  <p>Screen Class:</p>
  
  <pre><code>package tm;
  
  import javax.swing.JFrame;
  
  public class Screen extends JFrame {
      private static final long serialVersionUID = 1L;
      private JFrame mainScreen;
      private Game mainGame;
      private Settings Settings;
  
      public Screen() {
          mainGame = new Game();
          Settings = new Settings();
  
          mainScreen = new JFrame();
          mainScreen.add(mainGame);
          mainScreen.setSize(Settings.GAME_WIDTH, Settings.GAME_HEIGHT);
          mainScreen.setTitle("Lolz");
          mainScreen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          mainScreen.setResizable(false);
          mainScreen.setVisible(true);
      }
  
      public static void main(String[] args) {
          new Screen();
      }
  
  }
  </code></pre>