title: Exception in thread "Thread-1" java.lang.NullPointerException that happens when I try to update my graph
body: <p>I edited a JFreeChart real time graph and now I get this error when I try to run it.  When I run it, the GUI will pop up its just the graph doesn't have the random data stream in.
  Any ideas would be a great help.</p>
  
  <pre><code>public class Therm extends ApplicationFrame implements ActionListener{
  
  private static TimeSeries ts;
  JTextArea text = new JTextArea("25");
  JTextArea degreeC = new JTextArea("degrees C");
  JTextArea degreeF = new JTextArea("degrees F");
  
  
  public Therm(final String title){
  super(title);
  
  
  ts = new TimeSeries("Data", Millisecond.class);
  TimeSeriesCollection data = new TimeSeriesCollection(ts);
  
  JFreeChart chart = create(data);
  JFrame frame = new JFrame("GraphTest");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  ChartPanel label = new ChartPanel(chart);
  frame.getContentPane().add(label);  
  
  
  ChartPanel chartPanel = new ChartPanel(chart);
  JButton buttonC = new JButton("Celsius");
  JButton buttonF = new JButton("Farenheit");
  JButton button1 = new JButton("Toggle Extension (60 and 300 seconds)");
  JButton buttonOff = new JButton("Turn Box");
  buttonC.setActionCommand("C");
  buttonC.addActionListener(this);
  buttonF.setActionCommand("F");
  buttonF.addActionListener(this);
  button1.setActionCommand("ADD");
  button1.addActionListener(this);
  buttonOff.setActionCommand("off");
  buttonOff.addActionListener(this);
  
  
  
  Font font = new Font ("Verdana", Font.BOLD, 26);
  text.setFont(font);
  degreeC.setFont(font);
  degreeF.setFont(font);
  
  
  JPanel graph = new JPanel(new BorderLayout());
  graph.add(chartPanel);
  chartPanel.setPreferredSize(new java.awt.Dimension(700,300));
  setContentPane(graph);
  
  
  JPanel content = new JPanel(new GridLayout(3,2));
  content.setLayout(new GridLayout(3,2));
  content.add(text);
  content.add(degreeC);
  content.add(buttonC);
  content.add(buttonF);
  content.add(button1);
  content.add(buttonOff);
  add(content,BorderLayout.SOUTH);
  chartPanel.setPreferredSize(new java.awt.Dimension(700,300));
  
  } 
  
  private JFreeChart create(final XYDataset data){
      JFreeChart chart = ChartFactory.createTimeSeriesChart(
          "Thermometer Reading",
          "Time",
          "Degrees",
          data,
          true,
          true,
          false
      );
  
      final XYPlot plot = chart.getXYPlot();
      ValueAxis axisy = plot.getDomainAxis();
      axisy.setFixedAutoRange(60000.0);
      axisy = plot.getRangeAxis();
      axisy.setRange(10.0,50.0);
      return chart;
      }
  
  
  
  public void actionPerformed(final ActionEvent e) {
      if (e.getActionCommand().equals("C")) {  
          degreeC.setText("degrees C");
      }
      if (e.getActionCommand().equals("F")){
          degreeC.setText("degrees F");
      }
      if (e.getActionCommand().equals("off")){
  
      }
  }
  
  
  public static void main(String[] args) throws IOException{
      gen myGen = new gen();
      new Thread(myGen).start();
  
  
  
      final Therm prog = new Therm("Thermometer Graph");
      prog.pack();
      prog.setVisible(true);
  }
  
  
  
  static class gen implements Runnable{
      public void run() {
          while(true) {
              int num = 25 + (int)(Math.random() * ((40 - 30) + 1));
              System.out.println(num);
              ts.addOrUpdate(new Millisecond(), num);
              System.out.println("HI");
              try {
                  Thread.sleep(20);
              }
              catch (InterruptedException ex) {
                  System.out.println(ex);
              }
  
          }
      }
  }
  }
  </code></pre>
  
  <p>EDIT: here is the new code that receives the error ""syntax error, insert "Classbody" to complete Class Declaration"" at 'gen'</p>
  
  <pre><code>static class gen{
      while(true) {
          // don't forget to make num final!
          final int num = 25 + (int)(Math.random() * ((40 - 30) + 1));
          System.out.println(num);
          SwingUtilities.invokeLater(new Runnable(){
            public void run() {
              ts.addOrUpdate(new Millisecond(), num);                
            }
          });
          // ts.addOrUpdate(new Millisecond(), num);
          System.out.println("HI");
          try {
              Thread.sleep(20);
          }
          catch (InterruptedException ex) {
              System.out.println(ex);
          }
      }
  }
  </code></pre>