title: Why isn't my method adding up the values in my other classes? (sscce included)
body: <p>So I'm very new to java.</p>
  
  <p>This program runs right now. It's an ordering system for food. It uses tabs with grids in each. Each tabs has its own prices.</p>
  
  <p>My problem is when I runs and compiles the program, it runs but the prices don't add up.
  Basically, in the GUI class listed below, there's a method that takes the prices from each tab and adds them up....except it's not doing that. It does appear but the "$0.00" isn't changing.</p>
  
  <p>Like I said it compiles, however, when I do press buttons, I can see the compiler comes up with this error:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  </code></pre>
  
  <p>This is the main class:</p>
  
  <pre><code>import javax.swing.JFrame;
  
  public class Pizzamain
  {
  
  
       public static void main (String[] args)
     {
        JFrame frame = new JFrame ("Pizza Mutt Ordering Service");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new PizzaMuttPanel());
        frame.pack();
        frame.setVisible(true);
  
  
      }
  
  }
  </code></pre>
  
  <p>This class holds all the GUI. It also adds up the prices in each tab. I commented out the other tabs.</p>
  
  <pre><code>import java.awt.*;
  import javax.swing.*;
  import java.awt.event.*;
  import java.text.NumberFormat;
  
  public class PizzaMuttPanel extends JPanel
  {
      private JLabel totalLabel;
     private double total;
  
  
  
  
      public PizzaMuttPanel()
     {
        setLayout (new BorderLayout());
  
        JLabel name = new JLabel("Pizza Mutt Ordering Service WOOF! WOOF!");
        JPanel namePanel = new JPanel();
        namePanel.add(name);
        add(namePanel, BorderLayout.NORTH);
  
        JTabbedPane mainTabPane = new JTabbedPane();
        mainTabPane.add("Pizza", new PizzaPanel());
       // mainTabPane.add("Drinks", new DrinksPanel());
       // mainTabPane.add("Specials", new SpecialsPanel());
        add(mainTabPane, BorderLayout.CENTER);
  
        total = 0.0;
        JPanel totalPanel = new JPanel();
        totalPanel.add (new JLabel("Your total is:"));
        totalLabel = new JLabel("$0.00");
        totalPanel.add(totalLabel);
        add(totalPanel, BorderLayout.SOUTH);
  
        }
  
  
  
     public void addTotal (double intake)
     {
        total += intake;
        NumberFormat dollars = NumberFormat.getCurrencyInstance();
        totalLabel.setText(dollars.format(total));
     }
  }
  </code></pre>
  
  <p>This an example of one of the tabs. Btw, ALL the tabs follow this logic. As you can see, in the action section, there's something that adds prices each time a button is pressed then relays the data to the GUI class.</p>
  
  <pre><code>import java.awt.*;
  import javax.swing.*;
  import java.awt.event.*;
  
  
  public class PizzaPanel extends JPanel
  {
  private double price;
  private final JButton pl;
  private final JButton ps;
  private final JButton cl;
  private final JButton cs;
  private final JButton vl;
  private final JButton vs;
  private PizzaMuttPanel mainPanel;
  
  
     public PizzaPanel()
     {
        setLayout (new GridLayout (2, 3));
  
        setBackground (Color.red);
  
        pl = new JButton ("Large Pepperoni: $7");
        ps = new JButton ("Small Pepperoni: $4");
        cl = new JButton ("Large Cheese: $6.50");
        cs = new JButton ("Small Cheese: $3.50");
        vl = new JButton ("Large Vegetable: $7");
        vs = new JButton ("Small Vegetable: $4");
  
        add (pl);
        add (ps);
        add (cl);
        add (cs);
        add (vl);
        add (vs);
  
  
  
        pl.addActionListener(new ButtonListener());
        ps.addActionListener(new ButtonListener());
        cl.addActionListener(new ButtonListener());
        cs.addActionListener(new ButtonListener());
        vl.addActionListener(new ButtonListener());
        vs.addActionListener(new ButtonListener());
  
  
  
     }  
  
            //Here we listen for button presses
  
           private class ButtonListener implements ActionListener
     {
                     public void actionPerformed (ActionEvent e)
                 {
                   if (e.getSource().equals(pl)) 
  
                       {
  
                         price+=7;
  
  
                        }
  
                  if(e.getSource().equals(ps)) 
  
                        {
  
                           price+=4;
  
  
                         } 
  
                    if (e.getSource().equals(cl)) 
                          {
  
                           price+=6.5;
  
  
                          }
  
                     if (e.getSource().equals(cs)) 
                          {
                           price+=3.5;
  
  
                          } 
                      if (e.getSource().equals(vl)) 
                          {
  
                           price+=7;
  
  
                          }
  
                     if (e.getSource().equals(vs)) 
                          {
  
                           price+=4;
  
  
                          }
       //This adds all the prices together.                    
                  mainPanel.addTotal(price);
  
          }}}
  </code></pre>