【发布时间】:2014-04-20 22:03:38
【问题描述】:
这对我来说似乎有点奇怪。我创建了一个静态整数数组,然后我试图为它分配一个值。但是我在degree[i] = 0 行得到了一个空指针异常。
由于我在分配之前没有读取值,所以我不明白为什么会出现 NullPointer 异常。
private static Integer[] degree;
public static void initDegree(int num_of_vertices) throws Exception{
for (int i = 0; i < num_of_vertices; i++) {
degree[i] = 0;
}
}
【问题讨论】:
-
你还没有初始化数组。
标签: java arrays nullpointerexception