title: Constructors not Creating Object -- Java
body: <p>I've been wrestling with this problem in one of my programs for about a week now, and I have no idea what I am doing wrong.
  For this assignment I'm basically making an array of Employee objects with 3 different types of employees (commission, salary, hourly). All three of the sub-classes extend the Employee class, which is abstract. </p>
  
  <p>Here is my code that calls the constructors for each class type:</p>
  
  <pre><code>    public boolean addEmployee(int empType, String first, String last, char mi, char gen, int empNum, boolean full, double amount)
      {
      employeeCount += 1;
  
      if (employeeCount &gt; EMPLOYEES_MAX) {
          System.out.println("ERROR: ARRAY FULL. UNABLE TO ADD NEW EMPLOYEE");
          return false;
      }
  
      else {
          switch (empType) {
              case 1:
              employees[employeeCount] = new HourlyEmployee(first, last, mi, gen, empNum, full, amount);
              break;
  
              case 2:
              employees[employeeCount] = new SalaryEmployee(first, last, mi, gen, empNum, full, amount);
              break;
  
              case 3:
              employees[employeeCount] = new CommissionEmployee(first, last, mi, gen, empNum, full, amount);
              break;
          }
          return true;
      }
  }
  </code></pre>
  
  <p>And here is the constructor for the salary employee, the other 2 are pretty much teh same as this.</p>
  
  <pre><code>public class SalaryEmployee extends Employee
  {
  private double salary;
  
  public SalaryEmployee(String first, String last, char midInit, char gen, int empNum, boolean full, double sal)
  {
      super(first, last, midInit, gen, empNum, full);
      salary = sal;
  }
  </code></pre>
  
  <p>The super constructor I have written which is called by this constructor follows:</p>
  
  <pre><code>abstract class Employee
  {
  protected String firstName;
  protected String lastName;
  protected char middleInitial;
  protected boolean fullTime;
  protected char gender;
  protected int employeeNum;
  
  public Employee(String first, String last, char midInit, char gen, int empNum, boolean full)
  {
      firstName = first;
      lastName = last;
      middleInitial = midInit;
      employeeNum = empNum;
      fullTime = full;
  
      switch (gen) {
          case 'M': case 'F': 
          case 'm': case 'f':
          gender = gen;
          break;
  
          default:
          gender = 'F';
      }
  }
  </code></pre>
  
  <p>As I've said before, I have no idea why its not creating the objects like it should. Whenever I go to print out the array or sort it or anything I always get either null or a null pointer exception. </p>
  
  <p>Any help would be greatly appreciated, thank you all so much!</p>
  
  <p>EDIT:</p>
  
  <p>Ok, heres where my Employee array is initialized.</p>
  
  <pre><code>public class EmployeeList
  {
  private final int EMPLOYEES_MAX = 50;
  private Employee employees[];
  private int employeeCount;
  
  public EmployeeList()
  {
      employees = new Employee[EMPLOYEES_MAX];
      employeeCount = 0;
  }
  </code></pre>
  
  <p>When I run it its like its still going through the constructors because the default method is not run, I just get null for some odd reason. Heres the output:</p>
  
  <p>Choose from the following options:
          1       Add Employee
          2       Process Employees by Type Submenu
          3       Remove Employee
          4       Sort Employees
          5       Calculate Weekly Payout
          6       Calculate Bonus
          7       Annual Raises
          8       Reset Week
          0       Quit
          Option: 1</p>
  
  <ol>
  <li>Hourly</li>
  <li>Salary</li>
  <li>Commission
  Enter Choice: 1</li>
  </ol>
  
  <p>Enter Last Name: Doe</p>
  
  <p>Enter First Name: Jane</p>
  
  <p>Enter Middle Initial: M</p>
  
  <p>Enter Gender: F</p>
  
  <p>Enter Employee Number: 1</p>
  
  <p>Full Time? (y/n): y</p>
  
  <p>Enter wage: 14</p>
  
  <p>Employee Added to List</p>
  
  <p>null</p>
  
  <p>Main Menu</p>
  
  <p>The null comes from my main class that calls a listAll() method, its supposed to list everything in the array. but instead just returns null.</p>
  
  <p>EDIT AGAIN:</p>
  
  <p>So here is the method that is supposed to list everything.</p>
  
  <pre><code>    public void listAll()
  {
      for(int x = 0; x &lt; employeeCount; x++)
          System.out.println(employees[x]);
  }
  </code></pre>
  
  <p>thanks for your help!</p>