Results 1 to 3 of 3
Thread: My constructor not called
- 09-20-2009, 02:06 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 92
- Rep Power
- 0
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.
Java 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
- 09-20-2009, 02:23 AM #2Java Code:
public void EmpDB(){
Should be:
Java Code:public EmpDB() {
Last edited by mrmatt1111; 09-20-2009 at 02:26 AM.
My Hobby Project: LegacyClone
- 09-20-2009, 02:38 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 92
- Rep Power
- 0
Similar Threads
-
[SOLVED] please help, this assignment is called resreveR
By einstein1234 in forum New To JavaReplies: 7Last Post: 04-26-2009, 04:56 AM -
Return objects called
By MV1 in forum New To JavaReplies: 7Last Post: 03-11-2009, 08:16 AM -
javascipt function is nt getting called
By pankaj_salwan in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12-20-2008, 09:13 AM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 10:10 AM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 10:01 AM
Bookmarks