-1
정렬하려고하는 특정 클래스의 ArrayList가 있습니다. 그러나 정렬 중에 NullPointerException이 발생합니다. 배열에서 예외를 일으키는 요소를 찾으려면 try-catch를 사용하여 내 명령을 래핑했습니다. 문제가되는 요소를 파악하기 위해 catch를 검사 할 수 있습니까?NullPointerException을 검사하십시오. 원인
List<SingleMeasurementValuePoint> sortedList = new ArrayList<SingleMeasurementValuePoint>(deviceMeasurementPoints);
try {
Collections.sort(sortedList, new TimeAndComponentSort());
} catch (Exception e) {
System.out.println();
}
비교기 내의 코드, TimeAndComponentSort는 예 :
public class TimeAndComponentSort implements Comparator<SingleMeasurementValuePoint> {
@Override
public int compare(SingleMeasurementValuePoint point1, SingleMeasurementValuePoint point2) {
int val = point1.compareTo(point2);
if (val == 0) {
return point1.getComponentId().compareTo(point2.getComponentId());
}
else {
return val;
}
}
}
왜 디버거를 사용하지 않습니까? – manouti
코드를 Comparator - TimeAndComponentSort에 게시 할 수 있습니다. – BatScream
나는 디버거를 사용하고 캐치 안에 서 있습니다. 어떻게 ArrayList 내의 4500 요소 중 하나가 예외의 원인인지 감지 할 수 있습니까? – user3370773