title: Null error when trying to draw line in JFrame
body: <p>I'm trying to make a recursive program that draws a Kosh Snowflake but but gives me an error when I try to run it. Apparently n is null even though I initialize it:</p>
  
  <pre><code>Line2D n = new Line2D.Double(x0,y0,x1,y1);
          g2.draw(n);
  </code></pre>
  
  <p>And here is the full program:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.geom.*;
  import javax.swing.*;
      class turtle{
      double direction,x,y;
      public turtle(double direction, double x, double y)
      {
          this.direction=0;
          this.x=0;
          this.y=0;
      }
      public void move(double length)
      {
          this.x=x+Math.sin(direction)*length;
          this.y=y+Math.cos(direction)*length;
      }
      public void rotate(double angle)
      {
          this.direction=angle;
      }
  }
  public class fractal extends JComponent
  {
      turtle t = new turtle(0,0,0);
      Graphics2D g2;
      public static void main(String [] args)
  {
      fractal p = new fractal();
      JPanel panel = new JPanel();
      p.fractal(300,3);
      panel.add(p);
      panel.setSize(900,900);
      panel.setVisible(true);
  }
  public void fractal(double length,double depth)
  {
      if(depth==0)
      {
          double x0=t.x;
          double y0=t.y;
          t.move(length/4);
          double x1=t.x;
          double y1=t.y;
          Line2D n = new Line2D.Double(x0,y0,x1,y1);
          g2.draw(n);
          x0=t.x;
          y0=t.y;
          t.rotate(60);
          t.move(length/4);
          x1=t.x;
          y1=t.y;
          g2.draw(new Line2D.Double(x0,y0,x1,y1));
          x0=t.x;
          y0=t.y;
          t.rotate(-60);
          t.move(length/4);
          x1=t.x;
          y1=t.y;
          g2.draw(new Line2D.Double(x0,y0,x1,y1));
          x0=t.x;
          y0=t.y;
          t.rotate(0);
          t.move(length/4);
          x1=t.x;
          y1=t.y;
          g2.draw(new Line2D.Double(x0,y0,x1,y1));
      }
      else
      {
          fractal(length/4,depth-1);
          g2.rotate(60);
          fractal(length/4,depth-1);
          g2.rotate(-60);
          fractal(length/4,depth-1);
          g2.rotate(0);
          fractal(length/4,depth-1);
      }
  }
  }
  </code></pre>