NullPointerException异常数组 [英] NullPointerException in array
问题描述
我不断收到的(见下文)一个NullPointerException异常。一切工作在C#罚款,但在android系统它打破?
arrDBNumbers已满,code被认为通过运行和计数的#1的量,#2,#3等至#49加入1〜arrFreq [Ⅰ] [1],以填补该arrFreq数的总数。
它贯穿if语句,直到ķ命中6中,其中arrDBNumbers [0] [6]为1,然后跳转内if语句,然后休息?我不知道怎么回事就在这里的任何建议
在此先感谢牛逼
整数[] [] = arrDBNumbers新的整数[100]; [8]
整数[] [] arrFreq =新的整数[49] [2];
的for(int i = 0; I< 49;我++){
对于(INT J = 0; J< 49; J ++){
为(中间体K = 1; K&7;; k ++){
如果(arrDBNumbers [j]的[K] ==第(i + 1)){
arrFreq [I] [1] ++; //<这里是我得到异常?
}
}
}
}
由于只是写
整数[] [] = arrFreq新的整数[49] [2];
的表示您已初始化所有的空
元素的数组,因为它是整数数组
对象并对象的默认值是空引用。的
因此,
arrFreq [I] [1] ++; //尝试空++;
给 NullPointerException异常
。
这不会有,如果你曾使用情况下的元的阵列,这将默认为 0
组成的数组。的
INT [] [] = arrFreq新INT [49] [2];
I keep getting a NullPointerException at (see below). Everything works fine in C#, but in android it breaks?
arrDBNumbers is full and code is supposed to run through and count the amount of #1, #2, #3 and so on to #49 adding 1 to arrFreq[i][1] to fill arrFreq with the total count of the numbers.
It runs through the if statement till k hits 6 where arrDBNumbers[0][6] is 1, then jumps inside if statement and then breaks? I'm not sure whats going on here any advice thanks in advance T
Integer[][] arrDBNumbers = new Integer[100][8];
Integer[][] arrFreq = new Integer[49][2];
for (int i = 0; i < 49; i++){
for (int j = 0; j < 49; j++){
for (int k = 1; k < 7; k++){
if (arrDBNumbers[j][k] == (i + 1)){
arrFreq[i][1]++; // < here is where I get Exception?
}
}
}
}
Because just writing
Integer[][] arrFreq = new Integer[49][2];
means you have initialized the array with all null
elements because it is an array of Integer
Objects and Object's default value will be null reference.
Hence,
arrFreq[i][1]++; // trying null++;
gives NullPointerException
.
This wouldn't have been the case if you had used an array of primitives, which will default to an array of 0
s.
int[][] arrFreq = new int[49][2];
这篇关于NullPointerException异常数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!