изменить код, как показано ниже:
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn=new Scanner(System.in);
emp=new EmployeeDetail[3];
for(int i=0;i<3;i++) {
emp[i] = new EmployeeDetail();
System.out.println("Enter the employee "+(i+1)+" name");
emp[i].EmpName=scn.nextLine();
System.out.println("Enter the employee "+(i+1)+" number");
emp[i].EmpNumber=Integer.parseInt(scn.nextLine());
System.out.println("Enter the employee "+(i+1)+" Mobile number");
emp[i].MobNumber=Long.parseLong(scn.nextLine());
System.out.println("Enter the employee "+(i+1)+" Salary");
emp[i].Salary=Float.parseFloat(scn.nextLine());
}
scn.close();
empDataoutput();
}
Посмотрите на emp[i] = new EmployeeDetail();
, где объект создается и добавляется в индекс массива emp.
emp=new EmployeeDetail[3];
создает массив EmployeeDetail размера 3, но со значением null
.