java Exception in thread "main" java.lang.NullPointerException

来源:百度知道 编辑:UC知道 时间:2024/07/05 05:35:44
一个简单的矩阵类,还没完成,碰到个问题,RT...
Exception in thread "main" java.lang.NullPointerException
at Matrix.SetMatrix(MyMatrix.java:40)
at MyMatrix.main(MyMatrix.java:54)
下面是代码,帮忙看下哈~~谢谢~~
//import java.util.Scanner;

class Matrix
{
int row;
int col;
int [][] array = new int[10][];

public Matrix(int a, int b)
{
row = a;
col = b;
}

public void SumMatrix(Matrix a, Matrix b)//矩阵相关
{
if(a.row != b.row || a.col != b.col)
System.out.println("两矩阵类型不同!");
else
{
this.row = a.row;
this.col = a.col;
for(int i = 0; i < this.row; i++)
{
for(int j = 0; j < this.col; j++)
this.array[i][j] = a.array[i][j] + b.array[i][j];
}
}
System.out.println("矩阵之和为:");
for(int i = 0; i < this.row; i++)
{
for(int j = 0; j < this.col; j++)

class Matrix
{
int row;
int col;
int [][] array = new int[10][];

public Matrix(int a, int b)
{
row = a;
col = b;
}

public void SumMatrix(Matrix a, Matrix b)//矩阵相关
{
if(a.row != b.row || a.col != b.col)
System.out.println("两矩阵类型不同!");
else
{
this.row = a.row;
this.col = a.col;
//二维数组初始化
for(int i=0;i<this.row;i++)
this.array[i] = new int[this.col];

for(int i = 0; i < this.row; i++)
{
for(int j = 0; j < this.col; j++)
this.array[i][j] = a.array[i][j] + b.array[i][j];
}
}
System.out.println("矩阵之和为:");
for(int i = 0; i < this.row; i++)
{
for(int j = 0; j < this.col; j++)
System.out.print(this.array[i][j] + " ");
System.out.println();
}
}

public void SetMatrix(int a, int b,