java空指针异常 for循环时,使用了值为null的变量

错误代码:

for(Map<String,Object> videoItemMap:learnVideoList){
  String videoStuId=MapUtils.getString(videoItemMap, "record_user_id");
  if(videoStuId==stuId){
    videoCostTime=MapUtils.getInteger(videoItemMap, "videoTime");
    break;
  }
}

请求进程错误,空指针错误,报空指针异常。紧跟的是错误代码的位置。

threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.ho.pc.service.impl.ClManager.getDailyS(ClManager.java:115)

经检查:该行代码中使用了值为null的List<Map<String,Object>> 型变量learnVideoList 。因此遍历之前,需要判null!!!

PS:为毛.NET没遇到过这类情况。。。

原文地址:https://www.cnblogs.com/siesteven/p/6183683.html