运行后一使用功能就会有空指针异常
import java.util.Scanner;
public class Test2022 {
public void show(GISStudent[] student){
}
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
GISStudent[] gisClass2022=new GISStudent[1000];
gisClass2022[0]=new GISStudent("S001","zhangsan","M",90,88);
gisClass2022[1]=new GISStudent("S002","lisi","M",80,90);
gisClass2022[2]=new GISStudent("S003","wangwu","F",95,85);
Scanner scan=new Scanner(System.in);
String a;
do {
System.out.println("请输入你想要执行的功能");
a=scan.next();
if(a.equals("O")){
for(int i=0;i<gisClass2022.length;i++){
for(int j=0;j<9-i;j++)
{
if(gisClass2022[j].getMath()<gisClass2022[j+1].getMath())
{
GISStudent student=gisClass2022[j];
gisClass2022[j]=gisClass2022[j+1];
gisClass2022[j+1]=student;
System.out.println("排序成功");
}
}
}
}
else if (a.equals("S")) {
for (int i = 0; i < gisClass2022.length; i++) {
System.out.println("学号:"+gisClass2022[i].getId()+" "+"姓名:"+gisClass2022[i].getName()+" "+"性别:"+gisClass2022[i].getSex()+" "+"数学成绩:"+gisClass2022[i].getMath()+" "+"英语成绩:"+gisClass2022[i].getEnglish());
}
}
else if (a.equals("D")) {
System.out.println("请输入你要删除的学生学号");
String id;
id=scan.next();
for (int i = 0; i < gisClass2022.length; i++) {
if (gisClass2022[i].getId().equals(id)) {
for (int j = i; j < gisClass2022.length; j++) {
gisClass2022[j]=gisClass2022[j+1];
}
System.out.println("删除成功");
}
else{
System.out.println("未找到该学生");
}
}
}
else if(a.equals("I")){
String id;
System.out.println("请输入你要插入到哪个学生之前,输入该学生学号");
id=scan.next();
for (int i = 0; i < gisClass2022.length; i++) {
if (gisClass2022[i].getId().equals(id)) {
for (int j=gisClass2022.length; j>i; j--) {
gisClass2022[j]=gisClass2022[j-1];
}
gisClass2022[i]=new GISStudent("S004","zhaosi","M",91,89);
System.out.println("插入成功");
}
}
}
else if (a.equals("C")) {
float english,math;
float sum=0;
for (int i = 0; i < gisClass2022.length; i++) {
sum=gisClass2022[i].getMath()+sum;
}
math=sum/gisClass2022.length;
for (int i = 0; i < gisClass2022.length; i++) {
sum=gisClass2022[i].getEnglish()+sum;
}
english=sum/gisClass2022.length;
System.out.println("数学平均成绩是"+math+"英语平均成绩是"+english);
}
else {
System.out.println("输入错误");
}
} while (!a.equals("E"));{
System.exit(1);
System.out.println("退出系统");
}
}
}
我不明白是什么情况明明已经创建了对象了,可它还会有异常。