title: I keep getting nullpointer exception for jtable getrowcount() method
body: <p>I am trying to create a table that can be filtered but I keep getting a null pointer exception for the getRowCount() method in my table model class.</p>
  
  <p>HomePagePanel(where my table is)</p>
  
  <pre><code>public class homepagePanel extends JPanel implements ActionListener {
  private JButton uploadEmail, viewEmail, logout, delete;
  private JLabel userLog;
  private JLabel tableLabel;
  private JScrollPane scrollPane;
  private EmailTableListener emailTableListener;
  //private EmailTablePanel EmailPanel;
  private HomePagePanelListener homepagePanelListener;
  private List&lt;Item&gt; dc;
  private Controller controller;
  private JTable table;
  private EmailTableModel emailModel;
  private JPopupMenu popup;
  private JTextField filterText;
  private JLabel filterLabel;
  private TableRowSorter&lt;EmailTableModel&gt; sorter;
  
  
  
  
  public homepagePanel() {
  
  
  
      controller = new Controller();
  
      userLog = new JLabel("Logged in:");
  
      uploadEmail = new JButton("Upload");
      viewEmail = new JButton("View");
      delete = new JButton("Delete");
      logout = new JButton("Log Out");
      tableLabel = new JLabel("Emails stored");
  
      //Email stuff
      emailModel = new EmailTableModel();
      sorter = new TableRowSorter&lt;EmailTableModel&gt;(emailModel);
      table = new JTable(emailModel);
      table.setRowSorter(sorter);
  
      //
      filterLabel = new JLabel("Filter Text: ", SwingConstants.TRAILING);
      filterText = new JTextField(10);
      filterLabel.setLabelFor(filterText);
  
      //documenet listener
      filterText.getDocument().addDocumentListener(new DocumentListener(){
  
          @Override
          public void changedUpdate(DocumentEvent e) {
              // TODO Auto-generated method stub
              newFilter();
          }
  
          @Override
          public void insertUpdate(DocumentEvent e) {
              // TODO Auto-generated method stub
              newFilter();
          }
  
          @Override
          public void removeUpdate(DocumentEvent e) {
              // TODO Auto-generated method stub
              newFilter();
          }
       });
  
  
  
  
  
  
      // Adds the table to a scrollpane
      scrollPane = new JScrollPane(table);
      scrollPane
              .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      scrollPane
              .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  
      popup = new JPopupMenu();
  
      JMenuItem removeItem = new JMenuItem("Delete row");
      popup.add(removeItem);
  
  
      //adds mouse listener to show 
      table.addMouseListener(new MouseAdapter(){
  
          public void mousePressed(MouseEvent e) {
              int row = table.rowAtPoint(e.getPoint());
              table.getSelectionModel().setSelectionInterval(row, row);
              if(e.getButton() == MouseEvent.BUTTON3){
                  popup.show(table, e.getX(), e.getY());//shows popup
  
              }
          }
  
      });
      //removeitem actionlistener
      removeItem.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e) {
              int row = table.getSelectedRow();
  
              if(emailTableListener != null){
                  emailTableListener.rowDeleted(row);
                  emailModel.fireTableRowsDeleted(row, row);
              }
          }
  
      });
      // EmailPanel = new EmailTablePanel();
  
  
  
      layoutComponents();
  
      viewEmail.addActionListener(this);
      uploadEmail.addActionListener(this);
      logout.addActionListener(this);
  
  private void newFilter(){
      RowFilter&lt;EmailTableModel, Object&gt; rf = null;
  
      try{
          rf = RowFilter.regexFilter(filterText.getText());
      }catch(java.util.regex.PatternSyntaxException e){
          return;
      }
      sorter.setRowFilter(rf);
  }
  </code></pre>
  
  <p>TableModel</p>
  
  <pre><code>package view;
  
  import java.util.List;
  
  import javax.swing.table.AbstractTableModel;
  
  import model.Item;
  
  public class EmailTableModel extends AbstractTableModel {
  
  private List&lt;Item&gt; dc;
  private String[] colNames = {"ID", "To", "From", "Subject", "Topic", "Message Content", "Comments", "Attachments"};
  
  public EmailTableModel(){
      //System.out.println(dc.size());
  }
  
  public String getColumnName(int column) {
      // TODO Auto-generated method stub
      return colNames[column];
  }
  
  
  public void setData(List&lt;Item&gt; dc){
      this.dc = dc;
  }
  @Override
  public int getColumnCount() {
      // TODO Auto-generated method stub
      return 8;
  }
  
  @Override
  public int getRowCount() {
      // TODO Auto-generated method stub
      return dc.size();
  }
  
  @Override
  public Object getValueAt(int row, int column) {
      Item item = dc.get(row);
  
      switch(column){
      case 0: 
          return item.getId();
      case 1:
          return item.getTo();
      case 2:
          return item.getFrom();
      case 3:
          return item.getSubject();
      case 4:
          return item.getTopic();
      case 5:
          return item.getMessageContent();
      case 6:
          return item.getComments();
      case 7:
          return item.getAttachments();
  
      }
      return null;
  }
  
  public Class getColumnClass(int column) {
      Class returnValue;
      // Verifying that the column exists(index &gt; 0 &amp;&amp; index &lt; number of
      // columns
      if ((column &gt;= 0) &amp;&amp; (column &lt; getColumnCount())) {
          returnValue = getValueAt(0, column).getClass();
      } else {
          // Returns the class for the item in the column
          returnValue = Object.class;
      }
      return returnValue;
  };
  </code></pre>
  
  <p>}</p>
  
  <p>database class(retriving data for jtable)</p>
  
  <pre><code>    public void loadItems() throws SQLException {
      //connects to the database
      getConnected();
      Items.clear();//clears the linked list
      String sql = "Select Id, Reciever, Sender, Subject, topic, Email_Content, Comments, Attachments from item order by Id";//querly for select statement
      Statement selectStatement = con.createStatement();
      ResultSet results = selectStatement.executeQuery(sql);
  
      while (results.next()) {
          int id = results.getInt("Id");
          String To = results.getString("Reciever");
          String From = results.getString("Sender");
          String Subject = results.getString("Subject");
          String topic = results.getString("topic");
          String Email_Content = results.getString("Email_Content");
          String Comments = results.getString("Comments");
          String Attachments = results.getString("Attachments");
  
          Item item = new Item(id, To, From, Subject, topic, Email_Content,
                  Comments, Attachments);
          Items.add(item);//add item to linked list
  
      }
  
  }
  </code></pre>
  
  <p>mainframe(where I set the data</p>
  
  <pre><code>loadItems(); //method used to load the data from the database
  HomepagePanel.setData(controller.getItems());//sets data 
  </code></pre>