title: Null pointer exception when using Graphics in JFrame (Swing)
body: <p>I am slowly learning java, and I have decided to try to build a tic tac toe game.  I dove off into trying to draw the board, and I found a simple method to draw lines that everyone said would work.  I have this so far:</p>
  
  <pre><code>    public void constructBoard() {
      JFrame frame = new JFrame("Tic Tac Toe");
      frame.setSize(600,600);
      frame.setVisible(true);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setLocationRelativeTo(null);
      frame.toFront();
      Graphics lines = new Graphics();
      lines = getGraphics();
      lines.drawLine(100,100,300,500);
      lines.setColor(Color.black);
    //  JLabel label = new JLabel ("Hello, World!", SwingConstants.CENTER);
    //  frame.add(label, BorderLayout.CENTER);
  }
  </code></pre>
  
  <p>My JFrame comes up, my title is there, but no line.  I have tried multiple things, among which waw a separate method for the line, such as:</p>
  
  <pre><code>public void drawBoard(Graphics lines){
       lines = getGraphics();
       lines.drawLine(100,100,300,500);
       lines.setColor(Color.black);
  }
  </code></pre>
  
  <p>But when I call this in my main class, it tells me I need something between the parentheses to match type Graphics.  My compiler (Eclipse) recommends null, but to me, that could be causing the null pointer exception.</p>
  
  <p>I have the construct board method in a Board class, with a constructor Board() with super() inside it.</p>
  
  <pre><code>    public Board(){
          super();
      }
  </code></pre>
  
  <p>I then have a main class that just makes an object of type Board and calls my methods.  I have searched everywhere I know to look, and everywhere says what I have is the way to draw a line.  Then others with null pointer exceptions that I found either haven't gotten a solution, or haven't gotten one that works for me.  I have tried DebugGraphics, putting it all in the main class, and lines = new Graphics(); but that gives me an error.  Thanks for any help.</p>
  
  <p>Full Board class:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics;
  
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  
  
  public class Board extends JPanel {
          public Board(){
              super();
          }
          public void constructBoard() {
              JFrame frame = new JFrame("Tic Tac Toe");
              frame.setSize(600,600);
              frame.setVisible(true);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.setLocationRelativeTo(null);
                  frame.toFront();
                  Graphics lines = new Graphics();
                  lines = getGraphics();
                  lines.drawLine(100,100,300,500);
              lines.setColor(Color.black);
              //  JLabel label = new JLabel ("Hello, World!", SwingConstants.CENTER);
              //  frame.add(label, BorderLayout.CENTER);
          }
  }
  </code></pre>
  
  <p>Full main class:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics;
  
  
  public class Main {
  
      /**
       * @param args
       */
              public static void main(String[] args) {
                  // TODO Auto-generated method stub
                      Board board = new Board();
                      board.constructBoard();
  
              }
  
  }
  </code></pre>