java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String

报错提示

java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String

代码

List<Map<String,String>> jjMaxList = jj202212Repository.getDayMaxElectricity(beginDayOfYesterday,endDayOfYesterDay);
BigDecimal bd1=new BigDecimal(jjMaxList.get(i).get("value"));
BigDecimal bd2=new BigDecimal(jjMinList.get(j).get("value"));
BigDecimal value = bd1.subtract(bd2);

出现报错提示

解决办法

加上String.valueOf()不再报错

BigDecimal bd1=new BigDecimal(String.valueOf(jjMaxList.get(i).get("value")));
BigDecimal bd2=new BigDecimal(String.valueOf(jjMinList.get(j).get("value")));
BigDecimal value = bd1.subtract(bd2);

你可能感兴趣的:(平时工作遇到的问题,java,jvm,开发语言)