title: NullPointerException with ArrayList<JPanel> Calculator GUI
body: <p>I'm designing a calculator console that will take in two values, create a new instance of a class AdditionProblem which will return JLabel arrays of the 2 addends of the problem, the sum, and the amounts carried from each place (it shows the work). I have a custom class that extends JPanel and an ArrayList of JPanels that represent each line of the Solved problem after the add button is clicked. The AdditionProblem class works just fine as well as the Main class. When the addition button is clicked after I created the console class to display the answer I get a null pointer exception on line 44 "row.add(new JPanel)". If you need to see the rest of my code please let me know and I will post it but to save time I will just post the Console class since the other classes have been working properly until I moved code over to this class.</p>
  
  <pre><code>package Main;
  
  import java.awt.Color;
  import java.awt.Dimension;
  import java.util.ArrayList;
  
  import javax.swing.BoxLayout;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  
  import Aritmathic.AdditionProblem;
  
  public class Console extends JPanel {
  
  private int width = 230, height = 260;
  private ArrayList&lt;JPanel&gt; rows;
  private ArrayList&lt;JLabel&gt; columns;
  
  private void init(){
  
      this.setPreferredSize(new Dimension(width, height));
      this.setBackground(Color.WHITE);
      this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  
  }
  
  public Console(){
  
      init();
  
  }
  
  public void printAnswer(AdditionProblem problem){
  
      int rowIndex = 0;
  
      JLabel[] sumLabels = problem.getSumLabels();
      JLabel[] addend1Labels = problem.getAddend1Labels();
      JLabel[] addend2Labels = problem.getAddend2Labels();
      JLabel[] carriedLabels = problem.getCarriedLabels();
  
      rows.add(new JPanel());
  
      for(int i = 0; i &lt; carriedLabels.length; i++){
          rows.get(rowIndex).add(carriedLabels[i]);
      }
  
      rowIndex++;
      rows.add(new JPanel());
  
      for(int i = 0; i &lt; addend1Labels.length; i++){
          rows.get(rowIndex).add(addend1Labels[i]);
      }
  
      rowIndex++;
      rows.add(new JPanel());
  
      for(int i = 0; i &lt; addend2Labels.length; i++){
          rows.get(rowIndex).add(addend2Labels[i]);
      }
  
      rowIndex++;
      rows.add(new JPanel());
  
      for(int i = 0; i &lt; sumLabels.length; i++){
          rows.get(rowIndex).add(new JLabel("__"));
      }
  
      rowIndex++;
      rows.add(new JPanel());
  
      for(int i = 0; i &lt; sumLabels.length; i++){
          rows.get(rowIndex).add(sumLabels[i]);
      }
  
      for(int i = 0; i &lt; rows.size(); i++){
          this.add(rows.get(i));
      }
  }
  
  }
  </code></pre>