element cannot be mapped to a null key

错误信息:

java.lang.NullPointerException: element cannot be mapped to a null key
	at java.util.Objects.requireNonNull(Objects.java:228)
	at java.util.stream.Collectors.lambda$groupingBy$45(Collectors.java:907)
	at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at com.runlion.sat.tms.service.impl.BillFeeServiceImpl.listTotalFee(BillFeeServiceImpl.java:269)

错误原因:

因为在使用JAVA8对字段进行分组时,没有对该字段进行非空判断,所以在加载时会出现问题。

解决办法

Map<Object, List<BillFeeVO>> feeGroup = feeVOList.stream().collect(Collectors.groupingBy(BillFeeVO::getBizOperator)); //报错代码
Map<Object, List<BillFeeVO>> feeGroup = feeVOList.stream().filter(item->StringUtil.isNotBlank(item.getBizOperator())).collect(Collectors.groupingBy(BillFeeVO::getBizOperator)); // 增加了字段非空过滤

element cannot be mapped to a null key

上一篇:android 布局


下一篇:create-react-app 构建的项目使用代理 proxy 解决跨域请求