我正在编写代码以从文件中读取一些记录并以特殊方式对它们进行排序。我尝试了这样的代码:
public class Main {
static class judgement implements Comparable<judgement> {
public int q;
public int d;
public int r;
public int compareTo(judgement j) {
int k = ((judgement) j).q;
return 0;
}
}
public static void method() throws Exception {
judgement[] judgements;
judgements = new judgement[18425];
try {
// fill the "judgements" array
} finally {
Arrays.sort(judgements);
}
}
public static void main(String[] args) throws Exception {
method();
}
}
但是我在函数 compareTo 中得到错误NullPointerException 。有人可以帮我解决这个问题吗?