DESKTOP-O1UAITJ_20200903-史鹏华

一,问题

刚开始做的时候误以为final Customer[] customers = new Customer[ 5 ] ;创建的是五个Customer的对象,与是我通customers[i].setBirthdate(date);给Birthdate字段赋值,后来这条语句customers[i].setBirthdate(date)报空指针异常。

      final Customer[] customers = new Customer[ 5 ] ;
    
    // 使用循环对 customers 数组进行初始化
    for( int i = 0 ; i < customers.length ; i++){
        // 随机产生 年份、月份、日期,并将据此创建 LocalDate 对象中
        
        LocalDate  date =  LocalDate.of(random.nextInt(2020),random.nextInt(11),random.nextInt(31));
        // 在这里创建 Customer 对象
          customers[i]=new Customer(date );
         // customers[i].setBirthdate(date)
    }

​ 解决:后来请教齐元朝才发现这条语句final Customer[] customers = new Customer[ 5 ] ;创建的只是个数组,改成 用这条语句创建对象赋值后customers[i]=new Customer(date );赋值后,程序运行成功。

 ####  二,吐槽

假期啊。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。