所以,我一直在思考爲什麼我的代碼沒有整夜工作,並經過多年的搜索沒有治療,我決定在這裏發佈。我上線接收NPE有:nullpointerexception數組
this.numbers[a][b] = new Integer(n[a][b]);
有了這個是我的全碼:
private int[][] numbers, temp, temp2;
private int a, b;
public Matrix(int[][] n)
{
System.out.println(n[0].length);
int numbers[][] = new int[n[0].length][n[1].length];
int temp[][] = new int[n[0].length-1][n[1].length-1];
int temp2[][] = new int[n[0].length][n[1].length];
for(a=0;a<n[0].length;a++)
for(b=0;b<n[1].length;b++)
{
this.numbers[a][b] = new Integer(n[a][b]);
this.temp2[a][b] = new Integer(n[a][b]);
}
this.xLength = n[0].length;
this.yLength = n[1].length;
}
我爲什麼我得到一個錯誤無能;儘管我確信這是一個簡單的錯誤。幫助讚賞。 (n [] []是一個完美的陣列)
我得到了同樣的錯誤[4,1],[7,1] – user1928958
'新的整數(N [A] [B])'就這樣,您的對象立即自動拆箱並丟棄。我不明白你爲什麼這樣做。 –
= new Integer(n [a] [b]);和= n [a] [b];沒有什麼不同。我只是迫不及待地想知道它是否會奏效。 – user1928958