0

Been stuck on this problem for a while now, the program displays a list of employees from a database, which it does fine but as soon as i attempt to run the program after adding another button that adds a new employee i am met with a: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

the null value is at line 64 in my table model object,

my code if it helps:

package EmployeeSearch;

import java.util.List;
import javax.swing.table.AbstractTableModel;

import EmployeeSearch.Employee;

class EmployeeTableModel extends AbstractTableModel {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private static final int LAST_NAME_COL = 0;
    private static final int FIRST_NAME_COL = 1;
    private static final int EMAIL_COL = 2;
    private static final int SALARY_COL = 3;

    private String[] columnNames = { "Last Name", "First Name", "Email",
            "Salary" };
    private List<Employee> employees;

    public EmployeeTableModel(List<Employee> theEmployees) {
        employees = theEmployees;
    }

    @Override
    public int getColumnCount() {
        return columnNames.length; 
    }

    @Override
    public int getRowCount() {
        return employees.size();
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public Object getValueAt(int row, int col) {

        Employee tempEmployee = employees.get(row);

        switch (col) {
        case LAST_NAME_COL:
            return tempEmployee.getLastName();
        case FIRST_NAME_COL:
            return tempEmployee.getFirstName();
        case EMAIL_COL:
            return tempEmployee.getEmail();
        case SALARY_COL:
            return tempEmployee.getSalary();
        default:
            return tempEmployee.getLastName();
        }
    }


    @Override
    public Class<? extends Object> getColumnClass(int c) {
        return getValueAt(0, c).getClass(); // Error Appears here

    }
}

Error list:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at /*EmployeeSearch.EmployeeTableModel.getColumnClass(EmployeeTableModel.java:64)
    at javax.swing.JTable.getColumnClass(Unknown Source)
    at javax.swing.JTable.getCellRenderer(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
    at javax.swing.plaf.ComponentUI.update(Unknown Source)
    at javax.swing.JComponent.paintComponent(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JViewport.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
    at javax.swing.RepaintManager.paint(Unknown Source)
    at javax.swing.JComponent._paintImmediately(Unknown Source)
    at javax.swing.JComponent.paintImmediately(Unknown Source)
    at javax.swing.RepaintManager$4.run(Unknown Source)
    at javax.swing.RepaintManager$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.access$1200(Unknown Source)
    at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)*/
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373

0 Answers0