我收到错误java.lang.IndexOutOfBoundsException:Index:0,Size:0

时间:2018-06-07 14:39:52

标签: java

List<ActivationDTO> digitalOtputs = activationsDto.stream()
                    .filter(x -> x.getOutputDevice().getAddress() == DeviceOutputAddress.SOL_01.getValue()
                            && x.getReaderActivation().getActionEventType().equals(val))
                    .collect(Collectors.toList());
            int time = 0;
            try {
                time = digitalOtputs.get(0).getReaderActivation().getActivationTime();
            } catch (Exception e) {
                logger.error(String.format("Error at time config %1$s", reader.getId()) + ". " + e);                
            }

1 个答案:

答案 0 :(得分:-1)

mabe结果为空,首先检查是否为null然后使用方法

if(digitalOtputs.get(0) != null && digitalOtputs.get(0).getReaderActivation() != null) {

      digitalOtputs.get(0).getReaderActivation().getActivationTime();

}