My constructor not called
Am in entry level java class with an assignment to create an employee object and extra credit to enable it to handle more than one employee. I have enough programming and knowledge of JAVA (working through Sun tutorials) that I need to challange myself with the extra credit, given that we really haven't read the chapter on if-else and operators yet.
Got the employee class working no problem. Decided to implement the multiple employee task using Map object. The code is not working, and when I step through the debugger, I find that the instance has not been initialized.
Code:
public class EmployeePay {
//This is the application class
static private Scanner input = new Scanner(System.in);
static private EmpDB MyEmpDB = new EmpDB();
static private String inputLine = "";
static private Emp empFoo = new Emp();
public static void main(String[] args) {
// initialization code
System.out.println(MyEmpDB);
// output string edu.dmacc.rdt.HW_2EC.EmpDB@1faba46 shows creation of
// class
// using eclipse
// more code
public class EmpDB {
private static Map<String, Emp> empMap;
// constructor
public void EmpDB(){
//debugger doesn't stop on breakpoint
empMap = new HashMap<String, Emp>();
} // db
public void addEmp(Emp emp) {
// I get here in debugger: empMap is Null;
// generates null pointer exception
if (empMap.containsKey(emp.getId()) == false) {
empMap.put(emp.getId(),emp);
} else {//END if null
JOptionPane.showMessageDialog(null, "ERR: Duplicate Key");
}
}//END addEmp
//More code to find, remove, etc. objects - moot at this point
I see a problem with the possibility of multiple instances, but that's not the problem. Need to instanciate the empMap object.