CustmerList类中:
//修改前
public Customer[] getAllCustomers() {
Customer[] customers=new Customer[total];
for(int i=0;i<total;i++) {
customers[i]=customers[i];
}
return customers;
}
//修改后
public Customer[] getAllCustomers() {
Customer[] custs=new Customer[total];
for(int i=0;i<total;i++) {
custs[i]=customers[i];
}
return custs;
}
CustomerView类中:
Customer[] custs=customerList.getAllCustomers();//获取全部客户
for (int i = 0; i < custs.length; i++) {//进行循环编号
Customer cust=custs[i];//第i个数组客户
System.out.println((i+1)+"\t\t"+cust.getName()+"\t"
+cust.getGender()+"\t\t"+cust.getAge()+"\t\t"
+cust.getPhone()+"\t\t"+cust.getEmail());
运行后一直显示“Exception in thread “main” java.lang.NullPointerException”,具体到代码中查看。发现由于两个类中变量名不统一导致了空指针异常,已解决