所以,我一直在思考为什么我的代码整晚都没有工作,经过多年无药可救的搜索,我决定在这里发帖。我收到了一条 NPE:
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[][] 是一个完美的数组)