title: Found a NullPointerException
body: <p>I was making my first calculator in DrJava and it returned a NullPointerException.  What am I doing wrong?</p>
  
  <pre><code>java.lang.NullPointerException
  </code></pre>
  
  <p>Here's the Java code:</p>
  
  <pre><code>import java.awt.GridLayout;
  import java.awt.Font;
  import java.awt.event.WindowListener;
  import java.awt.event.WindowAdapter;
  import java.awt.event.WindowEvent;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JTextField;
  import javax.swing.JLabel;
  
  
  class calculadoraExercicio1 extends JFrame implements ActionListener
  {
    JButton buttonDigit1, buttonDigit2, buttonDigit3, buttonDigit4, buttonDigit5, buttonDigit6, buttonDigit7, 
            buttonDigit8, buttonDigit9, buttonDigit0, buttonAddition, buttonSubtraction, buttonMultiplication, 
            buttonDivision, buttonClean, buttonEquals, buttonDecimal;
    JLabel mainCalculadora, labelNull1, labelNull2, labelNull3, labelNull4, labelNull5;
    calculadoraExercicio1()
    {
      setTitle("Calculadora");
      setSize(800,600);
      setResizable(false);
      setUndecorated(true);
      getContentPane().setLayout(new GridLayout());
      mainCalculadora = new JLabel("0");
      buttonDigit1 = new JButton("1");
      buttonDigit1.addActionListener(new ActionListener() {
        public+ void actionPerformed(ActionEvent e)
        {
          if (mainCalculadora.getText() != "0") {
          mainCalculadora.setText(mainCalculadora.getText() + "1");
          }
          else
          {
          mainCalculadora.setText("1");
          }
        }
      });
      buttonDigit1.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDigit2 = new JButton("2");
      buttonDigit2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
          if (mainCalculadora.getText() != "0") {
          mainCalculadora.setText(mainCalculadora.getText() + "2");
          }
          else
          {
          mainCalculadora.setText("2");
          }
        }
      });
      buttonDigit2.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDigit3 = new JButton("3");
      buttonDigit3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
          if (mainCalculadora.getText() != "0") {
          mainCalculadora.setText(mainCalculadora.getText() + "3");
          }
          else
          {
          mainCalculadora.setText("3");
          }
        }
      });
      buttonDigit3.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDigit4 = new JButton("4");
      buttonDigit4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
          if (mainCalculadora.getText() != "0") {
          mainCalculadora.setText(mainCalculadora.getText() + "4");
          }
          else
          {
          mainCalculadora.setText("4");
          }
        }
      });
      buttonDigit4.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDigit5 = new JButton("5");
      buttonDigit5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
          if (mainCalculadora.getText() != "0") {
          mainCalculadora.setText(mainCalculadora.getText() + "5");
          }
          else
          {
          mainCalculadora.setText("5");
          }
        }
      });
      buttonDigit5.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDigit6 = new JButton("6");
      buttonDigit6.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
          if (mainCalculadora.getText() != "0") {
          mainCalculadora.setText(mainCalculadora.getText() + "6");
          }
          else
          {
          mainCalculadora.setText("6");
          }
        }
      });
      buttonDigit6.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDigit7 = new JButton("7");
      buttonDigit7.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
          if (mainCalculadora.getText() != "0") {
          mainCalculadora.setText(mainCalculadora.getText() + "7");
          }
          else
          {
          mainCalculadora.setText("7");
          }
        }
      });
      buttonDigit7.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDigit8 = new JButton("8");
      buttonDigit8.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
          if (mainCalculadora.getText() != "0") {
          mainCalculadora.setText(mainCalculadora.getText() + "8");
          }
          else
          {
          mainCalculadora.setText("8");
          }
        }
      });
      buttonDigit8.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDigit9 = new JButton("9");
      buttonDigit9.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
          if (mainCalculadora.getText() != "0") {
          mainCalculadora.setText(mainCalculadora.getText() + "9");
          }
          else
          {
          mainCalculadora.setText("9");
          }
        }
      });
      buttonDigit9.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDigit0 = new JButton("0");
      buttonDigit0.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
          if (mainCalculadora.getText() != "0") {
            mainCalculadora.setText(mainCalculadora.getText() + "0");
          }
        }
      });
      buttonDigit0.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDecimal = new JButton(",");
      buttonDecimal.addActionListener(this);
      buttonDecimal.setFont(new Font("Arial", Font.BOLD, 27));
      buttonAddition = new JButton("+");
      buttonAddition.addActionListener(this);
      buttonAddition.setFont(new Font("Arial", Font.BOLD, 27));
      buttonSubtraction = new JButton("-");
      buttonSubtraction.addActionListener(this);
      buttonSubtraction.setFont(new Font("Arial", Font.BOLD, 27));
      buttonMultiplication = new JButton("x");
      buttonMultiplication.addActionListener(this);
      buttonMultiplication.setFont(new Font("Arial", Font.BOLD, 27));
      buttonDivision = new JButton("÷");
      buttonDivision.addActionListener(this);
      buttonDivision.setFont(new Font("Arial", Font.BOLD, 27));
  
      getContentPane().add(labelNull1);
      getContentPane().add(mainCalculadora);
      getContentPane().add(labelNull2);
      getContentPane().add(labelNull3);
      getContentPane().add(labelNull4);
      getContentPane().add(buttonDigit1);
      getContentPane().add(buttonDigit2);
      getContentPane().add(buttonDigit3);
      getContentPane().add(buttonClean);
      getContentPane().add(buttonDecimal);
      getContentPane().add(buttonDigit4);
      getContentPane().add(buttonDigit5);
      getContentPane().add(buttonDigit6);
      getContentPane().add(buttonAddition);
      getContentPane().add(buttonSubtraction);
      getContentPane().add(buttonDigit7);
      getContentPane().add(buttonDigit8);
      getContentPane().add(buttonDigit9);
      getContentPane().add(buttonMultiplication);
      getContentPane().add(buttonDivision);
      getContentPane().add(buttonDigit0);
      getContentPane().add(labelNull5);
      getContentPane().add(buttonEquals);
    }
     public void actionPerformed(ActionEvent e)
    {
       String s = "";
       float r = 0;
       boolean d = false;
      if(e.getSource() == buttonClean)
      {
        mainCalculadora.setText("0");
      }
      if(e.getSource() == buttonDecimal)
      {
        if (d = false) {
        mainCalculadora.setText(mainCalculadora.getText() + ",");
        d = true;
        }
      }
      if(e.getSource() == buttonAddition)
      {
        s = "+";
      }
      if(e.getSource() == buttonSubtraction)
      {
        s = "-";
      }
      if(e.getSource() == buttonMultiplication)
      {
        s = "*";
      }
      if(e.getSource() == buttonDivision)
      {
        s = "/";
      }
      if(e.getSource() == buttonEquals)
      {
        if (s == "+") {
          r = r + Float.parseFloat(mainCalculadora.getText());
          mainCalculadora.setText(String.valueOf(r));
        }
        if (s == "-") {
          r = r - Float.parseFloat(mainCalculadora.getText());
          mainCalculadora.setText(String.valueOf(r));
        }
        if (s == "*") {
          r = r * Float.parseFloat(mainCalculadora.getText());
          mainCalculadora.setText(String.valueOf(r));
        }
        if (s == "/") {
          r = r / Float.parseFloat(mainCalculadora.getText());
          mainCalculadora.setText(String.valueOf(r));
        }
      }
    }
     public static void main (String args[])
    {
      JFrame Janela = new calculadoraExercicio1();
      Janela.show(); 
      WindowListener x = new WindowAdapter()
      {
        public void windowClosing(WindowEvent e)
        {
          System.exit(0);
        }
      };
      Janela.addWindowListener(x);
    }
  }
  </code></pre>
  
  <p>I don't know what I'm doing wrong.</p>