title: java.lang.NullPointerException on method
body: <p>I receive a java.lang.NullPointerException when I click the button in this java application.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class MRA_JFrame extends JFrame implements ActionListener
  {
      private JTextField ageField;
      private JTextField smokesField;
      private JTextField overweightField;
      private JButton reportButton;
      private JTextArea log;
      private Patient patient;
  
      public MRA_JFrame()
      {
          super("GDM's Medical risk assessment");
          setSize(500, 300);
          setLocation(200, 200);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
  
          setupGUI();
  
          setVisible(true);
          ageField.requestFocus();
      }
  
      public void setupGUI()
      {
          JPanel westPanel = setupWestPanel();
          JPanel centrePanel = setupCenterPanel();
  
          getContentPane().setLayout(new BorderLayout(5, 5));
          getContentPane().setBackground(Color.DARK_GRAY);
          getContentPane().add(westPanel, BorderLayout.WEST);
          getContentPane().add(centrePanel, BorderLayout.CENTER);
      }
  
      public JPanel setupCenterPanel()
      {
          Font f = new Font("Courier New", Font.PLAIN, 12);
  
          log = new JTextArea(5, 20);
          log.setEditable(false);
          log.setFont(f);
  
          JPanel p = new JPanel(new GridLayout(1, 1));
          p.add(new JScrollPane(log));
          return p;
      }
  
      public JPanel setupWestPanel()
      {
          JPanel wnPanel = setupWestNorthPanel();
          JPanel wsPanel = setupWestSouthPanel();
  
          JPanel p = new JPanel(new BorderLayout());
          p.add(wnPanel, BorderLayout.NORTH);
          p.add(wsPanel, BorderLayout.SOUTH);
          return p;
      }
  
      public JPanel setupWestNorthPanel()
      {
          ageField = new JTextField(5);
          smokesField = new JTextField(5);
          overweightField = new JTextField(5);
  
          JPanel agePanel = new JPanel(new GridLayout(1, 2));
          agePanel.add(new JLabel("Age: ", JLabel.RIGHT));
          JPanel p = new JPanel();
          p.add(ageField);
          agePanel.add(p);
  
          JPanel smokesPanel = new JPanel(new GridLayout(1, 2));
          smokesPanel.add(new JLabel("Smokes: ", JLabel.RIGHT));
          p = new JPanel();
          p.add(smokesField);
          smokesPanel.add(p);
  
          JPanel overweightPanel = new JPanel(new GridLayout(1, 2));
          overweightPanel.add(new JLabel("Overweight: ", JLabel.RIGHT));
          p = new JPanel();
          p.add(overweightField);
          overweightPanel.add(p);
  
          JPanel np = new JPanel();
          np.setLayout(new BoxLayout(np, BoxLayout.Y_AXIS));
          np.add(agePanel);
          np.add(smokesPanel);
          np.add(overweightPanel);
  
          return np;
      }
  
      public JPanel setupWestSouthPanel()
      {
          reportButton = new JButton("Report");
          reportButton.addActionListener(this);
  
          JPanel p = new JPanel();
          p.add(reportButton);
  
          return p;
      }
  
      @Override
      public void actionPerformed(ActionEvent e)
      {
          if(e.getSource() == reportButton)
          {
              System.out.println("I'm Clicked!");
              patient.setAge(ageField, log);
          }
      }
  </code></pre>
  
  <p>the Patient class is as follows.</p>
  
  <pre><code>import javax.swing.*;
  
  public class Patient 
  {
      private int age;
      private String smoker;
      private String overweight;
  
      // Consturctor
      public Patient()
      {
          age = 0;
          smoker = "n";
          overweight = "n";  
      }
  
      public void setAge(JTextField age, JTextArea log)
      {
          try
          {
              this.age = Integer.parseInt(age.getText());
  
          }
          catch(NumberFormatException nfe)
          {
              log.append("Age must be an integer");
  
          }
      }
  
      public void setSmoker(JTextField smoker, JTextArea log)
      {
          if(smoker.getText().equalsIgnoreCase("y") || smoker.getText().equalsIgnoreCase("n"))
          {
              this.smoker = smoker.getText();
  
          }
          else
          {
              log.append("Smokes must be one 'y', 'Y', 'n' or 'N'");
          }
      }
  
      public void setOverweight(JTextField overweight, JTextArea log)
      {
          if(overweight.getText().equalsIgnoreCase("y") || overweight.getText().equalsIgnoreCase("n"))
          {
              this.overweight = overweight.getText();
  
          }
          else
          {
              log.append("overweight must be one 'y', 'Y', 'n' or 'N'");
          }
      }
  }        
  </code></pre>
  
  <p>The application will list the variables of the patient reported and tell the user if they have used incorrect inputs in their report.</p>