This is my EmpData Class:
package com.bank;
public class EmpData {
int id;
String name;
String date;
String pos;
String status;
public void setEmp(int id, String name, String date) {
this.id = id;
this.name = name;
this.date = date;
}
public void setStat(String pos, String stat){
this.pos = pos;
this.status = stat;
}
public void disp(){
System.out.println(id+" : "+name+" : "+date+" : "+pos+" : "+status);
}
}
This is my Main Class:
package com.bank;
public class Bank {
public static void main(String[] args) {
EmpData[] obj = new EmpData[4];
obj[1].setEmp(1, "Test123", "09-04-1990");
obj[1].setStat("clerk", "on-hold");
obj[1].disp();
}
}
i got no syntax error in eclipse, but when i run the program i get the following null pointer error
Exception in thread “main” java.lang.NullPointerException
at com.bank.Bank.main(Bank.java:6)
You are not initializing
obj[1]before setting values..as it should be