String maxOutflowRate1 = relayLinkReport.getMaxOutflowRate(); if (ObjectUtil.isEmpty(maxInflowRate1)) { maxOutflowRate1 = "0.0"; } BigDecimal maxOutflowRate = new BigDecimal(maxOutflowRate1).add(new BigDecimal(setRelayLinkValue(object.getMaxOutflowRate()))); 这些代码报空指针咋回事
时间: 2024-01-25 18:02:47 浏览: 92
ObjectUtil.java
根据你提供的代码,可能是`relayLinkReport`或`object`中的`getMaxOutflowRate()`方法返回了`null`,导致在调用`isEmpty()`方法时出现了`NullPointerException`异常。你可以在调用`getMaxOutflowRate()`方法之前,先做一个非空判断,例如:
```
String maxOutflowRate1 = relayLinkReport.getMaxOutflowRate();
if (maxOutflowRate1 == null) {
maxOutflowRate1 = "0.0";
}
BigDecimal maxOutflowRate = new BigDecimal(maxOutflowRate1).add(new BigDecimal(setRelayLinkValue(object.getMaxOutflowRate())));
```
或者你也可以在方法中添加一个断言,检查`relayLinkReport`和`object`是否为空:
```
assert relayLinkReport != null && object != null;
String maxOutflowRate1 = relayLinkReport.getMaxOutflowRate();
if (ObjectUtil.isEmpty(maxInflowRate1)) {
maxOutflowRate1 = "0.0";
}
BigDecimal maxOutflowRate = new BigDecimal(maxOutflowRate1).add(new BigDecimal(setRelayLinkValue(object.getMaxOutflowRate())));
```
这样,如果`relayLinkReport`或`object`为空,就会抛出`AssertionError`,帮助你更快地定位问题。
阅读全文