Results 1 to 3 of 3
  1. #1
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Rep Power

    Default 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(;
    	static private EmpDB MyEmpDB = new EmpDB();
    	static private String inputLine = "";
    	static private Emp empFoo = new Emp();
    	public static void main(String[] args) {
    // initialization code
    //  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) {	
    		} 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.

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    San Jose, CA, USA
    Rep Power


    Java Code:
    public void EmpDB(){

    Should be:

    Java Code:
    public EmpDB() {
    Last edited by mrmatt1111; 09-20-2009 at 01:26 AM.
    My Hobby Project: LegacyClone

  3. #3
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Rep Power


    Thanks for quick posting. I was just going to post that I found the problem. You are right, and I'm sure I don't need to tell you that.

Similar Threads

  1. [SOLVED] please help, this assignment is called resreveR
    By einstein1234 in forum New To Java
    Replies: 7
    Last Post: 04-26-2009, 03:56 AM
  2. Return objects called
    By MV1 in forum New To Java
    Replies: 7
    Last Post: 03-11-2009, 07:16 AM
  3. javascipt function is nt getting called
    By pankaj_salwan in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-20-2008, 08:13 AM
  4. Replies: 0
    Last Post: 12-19-2007, 09:10 AM
  5. Replies: 0
    Last Post: 12-19-2007, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts