gpt4 book ai didi

java - 如何防止 date.getMillisOf 空指针异常?

转载 作者:行者123 更新时间:2023-12-04 09:41:52 26 4
gpt4 key购买 nike

oldScoreByPriorityMap.get(key).getCalculationDate()有问题.在本节中如何防止millis 抛出空指针异常?

异常(exception)

[29.05.2020 17|callto:29.05.2020 17]:01:37,619 ERROR java.lang.NullPointerException
java.lang.NullPointerException
at java.util.Date.getMillisOf(Date.java:958)
at java.util.Date.after(Date.java:931)
at tr.com.model.report.objects.ReportTableObject.setOldScoreByPriorityMap(ReportTableObject.java:80)
at tr.com.model.report.objects.ReportTableObject.setCpty(ReportTableObject.java:26)

RaportTableObject.java
    String key = scoreByPriority.getRuleEngineSetup().getName();
if(oldScoreByPriorityMap.containsKey(scoreByPriority.getRuleEngineSetup().getName())) {
if(scoreByPriority.getCalculationDate()!=null && scoreByPriority.getCalculationDate().after(oldScoreByPriorityMap.get(key).getCalculationDate()))
oldScoreByPriorityMap.put(key, scoreByPriority);
}else {
oldScoreByPriorityMap.put(key, scoreByPriority);
}

日期.java
public boolean after(Date when) {
return getMillisOf(this) > getMillisOf(when);
}

最佳答案

这可能会帮助你

    String key = scoreByPriority.getRuleEngineSetup().getName();
if(oldScoreByPriorityMap.containsKey(scoreByPriority.getRuleEngineSetup().getName()) && oldScoreByPriorityMap.get(key).getCalculationDate() != null) {
if(scoreByPriority.getCalculationDate() != null && scoreByPriority.getCalculationDate().after(oldScoreByPriorityMap.get(key).getCalculationDate()))
oldScoreByPriorityMap.put(key, scoreByPriority);
}else {
oldScoreByPriorityMap.put(key, scoreByPriority);
}

关于java - 如何防止 date.getMillisOf 空指针异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62298662/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com