大神们,帮忙看一下为什么会有空指针报错..
import java.util.*;public class StudentEbo {
Student[] arr=new Student[0];
public static void main(String[] args){
Scanner in=new Scanner(System.in);
System.out.println("请输入学生人数:");
StudentEbo.add(in.nextInt());
}
public static void add(int num){
if(arr.length<num){
Student[] tempArr=new Student[arr.length+1];
Scanner in=new Scanner(System.in);
Student st=new Student();
System.out.println("请输入学生姓名:");
st.setName(in.next());
System.out.println("请输入学生年龄:");
st.setAge(in.nextInt());
st.setOn(arr.length+1);
tempArr[arr.length]=st;
arr=tempArr;
printAll();
}
}
public static void printAll(){
System.out.println("\t编号\t姓名\t年龄\tjava\tC#\thtml\tsql\t总分\t平均分");
for(int i=0;i<arr.length;i++){
System.out.println("\t"+arr[i].getOn()+"\t"+arr[i].getName()+"\t"+arr[i].getAge()+"\t"+arr[i].getJava()+"\t"+arr[i].getC_shar()
+"\t"+arr[i].getHtml()+"\t"+arr[i].getSql()+"\t"+arr[i].getSum()+"\t"+arr[i].getAvg());
}
}
}
StudentEbo.rar
(877 Bytes)