Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8549075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:38:33+00:00 2026-06-11T13:38:33+00:00

Heres the full error Exception in thread main java.lang.NullPointerException at EmployeeManager.addEmployee(EmployeeManager.java:38) at EmployeeDriver.main(EmployeeDriver.java:231) here

  • 0

Heres the full error

Exception in thread "main" java.lang.NullPointerException
    at EmployeeManager.addEmployee(EmployeeManager.java:38)
    at EmployeeDriver.main(EmployeeDriver.java:231)

here is where the errors are coming from

public class EmployeeManager
{
private Employee[] employees;
private final int employeeMax = 100;
private int currentEmployees;

public EmployeeManager()
{
    Employee[] employees = new Employee[employeeMax];
    currentEmployees = 0;
}

public void addEmployee(int eType, String fn, String ln, char m, char g, int empNum, boolean ft, double a)
{
    double sales = 0.0, hoursWorked = 0.0;
    switch (eType)
    {
       /*error*/ case 1: employees[currentEmployees] = new HourlyEmployee(fn, ln, m, g, empNum, ft, a, hoursWorked);
                currentEmployees++;
                break;

        case 2: employees[currentEmployees] = new SalaryEmployee(fn, ln, m, g, empNum, ft, a);
                currentEmployees++;
                break;

        case 3: employees[currentEmployees] = new CommissionEmployee(fn, ln, m, g, empNum, ft, a, sales);
                currentEmployees++;
                break;
    }
}

///////////////////////////////////////////////////////////////////////////////////////////

 //Add Employee
            case 2:
                String fn, ln;
                char mi, g, f;
                boolean ft = true;
                do
                {
                    System.out.println("\n1. Hourly");
                    System.out.println("2. Salary");
                    System.out.println("3. Commission");
                    System.out.print("Enter Choice: ");
                    subInput1 = in.nextInt();

                    if(subInput1 < 1 || subInput1 > 3)
                    {
                        System.out.println("Invalid Choice! Choose again.");
                    }
                }while(subInput1 < 1 || subInput1 > 3);

                System.out.print("Enter Last Name: ");
                ln = in.next();
                System.out.print("Enter First Name: ");
                fn = in.next();
                System.out.print("Enter Middle Initial: ");
                mi = in.next().charAt(0);
                System.out.print("Enter Gender: ");
                g = in.next().charAt(0);
                System.out.print("Enter Employee Number: ");
                en = in.nextInt();
                System.out.print("Full Time? (y/n): ");
                f = in.next().charAt(0);
                if(f == 'n' || f == 'N')
                {
                    ft = false;
                }

                if(subInput1 == 1)
                {
                    System.out.print("Enter wage: ");
                }
                else if(subInput1 == 2)
                {
                    System.out.print("Enter salary: ");
                }
                else
                {
                    System.out.print("Enter rate: ");
                }
                amount = in.nextDouble();

     /*error*/  em.addEmployee(subInput1, fn, ln , mi, g, en, ft, amount);
                em.removeRedundancies();
                break;

Now as far as i am concerned i am making a new instantiation of HourlyEmployee which holds all of these values in the employees array. HourlyEmployee is a subclass of superclass Employee. Here’s my code for those two.

public class HourlyEmployee extends Employee
{
private double wage;
private double hoursWorked;

public HourlyEmployee(String fn, String ln, char m, char g, int empNum, boolean ft, double w, double h)
{
    super (fn, ln, m, g, empNum, ft);
    wage = w;
    hoursWorked = h;
    hoursWorked = 0.0;
}

@Override
public String toString()
{
    return this.getEmployeeNumber() + "\n" + lastName + ", " + firstName + middleInitial + "\n" + "Gender: "
     + this.getGender() + "\n" + "Status: " + fulltime + "\n" + "Wage: " + wage + "\n" + "Hours Worked: " + hoursWorked + "\n";
}

@Override
public double calculateWeeklyPay()
{
    if (hoursWorked > 40)
    {
        wage = wage * 2;
    }

    return wage * hoursWorked;
}

@Override
public void annualRaise()
{
    wage = (wage * .05) + wage;
}

@Override
public double holidayBonus()
{
    return wage * 40;
}

@Override
public void resetWeek()
{
    hoursWorked = 0.0;
}

public double plusHoursWorked(double amount, double h)
{
    while (amount <= 0)
    {
        System.out.println("Invalid value entered, please try again");
    }

    return amount + h;
}


}

///////////////////////////////////////////////////////////////////////////////////////////

public abstract class Employee
{
protected String firstName;
protected String lastName;
protected char middleInitial;
protected boolean fulltime;
private char gender;
private int employeeNum;

public Employee (String fn, String ln, char m, char g, int empNum, boolean ft)
{
    firstName = fn;
    lastName = ln;
    middleInitial = m;
    gender = g;
    employeeNum = empNum;
    fulltime = ft;
}

public int getEmployeeNumber()
{
    return employeeNum;
}

public void setEmployeeNumber(int empNum)
{
    while (empNum <= 10000 && empNum >= 99999)
    {
        System.out.print ("Invalid input, please try again: ");
    }

    if (empNum >= 10000 && empNum <= 99999)
    {
        employeeNum = empNum;
    }
}

public String getFirstName()
{
    return firstName;
}

public String getLastName()
{
    return lastName;
}

public char checkGender(char g)
{
    if (g != 'M' || g != 'F')
    {
        g = 'F';
    }
    return g;
}
public char getGender()
{
    return gender;
}

@Override
public boolean equals(Object e2)
{
    if (this.employeeNum == ((Employee)e2).employeeNum)
    {
        return true;
    }
    else
    {
        return false;
    }
}

@Override
public String toString()
{
    return employeeNum + "\n" + lastName + ", " + firstName + "\n" + "Gender:" + gender + "\n" + "Status:" + fulltime + "\n";
}

public abstract double calculateWeeklyPay();

public abstract void annualRaise();

public abstract double holidayBonus();

public abstract void resetWeek();
}

I honestly have no idea what I am doing wrong, if someone could point me in the right direction I would really appreciate it. Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:38:34+00:00Added an answer on June 11, 2026 at 1:38 pm

    Local declaration of

    Employee[] employees = new Employee[employeeMax];
    

    hides the instance variable, try with:

    employees = new Employee[employeeMax];
    

    otherwise the employees you are instantiating is a local variable which disappears after the call to the constructor.

    In your situation you have

    Employees[] e = NULL;
    
    method()
    {
       Employees[] e = new Employees[N]; // this declares a different variable with same name
    }
    
    method2()
    {
      .. e[0] .. // exception: e was still NULL
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See the full error here: http://notesapp.heroku.com/ I'm using DataMapper and dm-validations 0.10.2. No matter
I am getting the common ASP.NET YSOD error. Here is the full error page
you can view full source code here dpaste.com/hold/167199 Error: delete() takes exactly 2 arguments
Here's my full, latest code that doesn't work. Here's the main window HTML <!DOCTYPE
The full error is: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]:
Can anyone help me with this error? alt text http://abbeylegal.com/downloads/parsererror.jpg full image here It
Here are the full codes that I am using to implement this program. Everything
Here's some code (full program follows later in the question): template <typename T> T
Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
Summary Below is the full question (a bit complicated in its full form) here's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.