I need help with calling methods from definition class using an array in main method.
public class Student{
private String id;
public void setId(String id){
this.id=id;
}
public String getId(){
return id;
}
}
and in main, with an array of students like this,
public static void main(String[] args){
int numOfStudent=0;
Student[] students = new Student[numOfStudent];
students[numOfStudent].setId(JOptionPane.showInputDialog("Enter id:"));
numOfStudent++;
}
I keep getting an error message saying
"java:6: error: cannot find symbol
students[numOfStudent].setId(JOptionPane.showInputDialog("Enter id:"));
symbol: variable JOptionPane location: class Whatever
1 error "
what is the problem here??
0. So, there won't be any element inside.