I created class Supervisor which contains the constructor and a toString method. However when I try to print an Index of the array an error occur,"Variable svArray might not have been initialized. What can I do to solve this ?
Supervisor[] svArray;
if (mainChoice == 3){
String ID, name, department, resarch;
System.out.println("Enter How Many Supervisor you want to enter : ");
svNumber = input.nextInt();
svArray = new Supervisor[svNumber];
for (int i = 0; i < svNumber; i++) {
System.out.println("---Enter Supervisor " + (i + 1) + " Of " + svNumber + " ---");
System.out.println("Enter staff ID : ");
ID = input.next();
System.out.println("Enter name : ");
name = input.next();
System.out.println("Enter department : ");
department = input.next();
svArray[i]=new Supervisor(ID, name, department);\
}
}
System.out.print(svArray[1].toString)
//Error, variable svArray might not have been initialized