我需要下面我的代碼的意外輸出幫助。 我創建了一個名爲「學生」的類,我稱之爲「MainStudent」,我沒有錯誤的代碼,當我嘗試將Student對象傳遞給Array並使用setter輸入數據時,但是當我運行我的代碼時,輸出是說,像這樣的:在線程 「主要」 顯示java.lang.NullPointerException陣列中的吸氣和吸氣器
異常
我使用NetBeans,以寫我的Java代碼。
import javax.swing.JOptionPane;
public class MainStudent {
public static void main(String[] args) {
String a,b;
int c;
Student[] std = new Student[3];
for(int i=0; i<std.length; i++){
a = JOptionPane.showInputDialog("Enter Student Name");
b = JOptionPane.showInputDialog("Enter Student Address");
c = Integer.parseInt(JOptionPane.showInputDialog("Enter Student Phone Number"));
std[i].setName(a);
std[i].setAddress(b);
std[i].setPhone_number(c);
}
for(int i=0; i<std.length; i++){
System.out.println(std[i].getName());
}
}
}