I am trying to create a program for an online Java course. This program includes an Employee class and a Name class. I have to create multiple Employee objects and prompt th
You created a new array with a size of numEmp, but the default value for each element is null. This means that the array initially contains numEmp null references. You need to use new to instantiate each Employee object before you can call methods on them.
You can either do this immediately after you create the array:
Employee employee[] = new Employee [ numEmp ];
for( int j = 0; j < numEmp; j++ )
{
employee[j] = new Employee();
}
Or you could do it inside your existing loop, just before you first need to use the object:
employee[j] = new Employee();
employee[j].setFirstName(nameF);