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 the user to enter the employee's name. I am storing all the Employee objects in an employee array.
Here's the code:
//Creates employee array with the number of array elements being however many
//employees there are:
Employee employee[] = new Employee [ numEmp ];
for( int j = 0; j < numEmp; j++ )
{
System.out.println( "Please enter the first name of employee number "
+ ( j + 1 ) );
Scanner input2 = new Scanner( System.in );
String nameF = input2.nextLine();
//This should set the employee object at employee array element "j" to the
//String nameF
employee[ j ].setFirstName( nameF );
The problem is that the compiler, while running the program, says that the last line is a NullPointerException. I'm not sure what I am doing wrong. Any suggestions?
Thanks! -Sean