我最初想说,感谢您花时间看我的文章。基本上我试图用Math.random创建一个随机整数的多维数组。代码编译并保持返回空指针异常错误消息。我不知道我在创建对象时做了什么错误。任何人都可以告诉我代码有什么问题吗?创建一个随机整数的多维数组
public Table(int r, int c)
{
rows = r;
columns = c;
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
{
/*
* Here is where the error keeps returning, blueJ keeps pointing
* me to this line of code and it has to be the variables I am using
* in the array that are causing the issue. The only issue is I * don't know what to insert for that.
*/
theTable[i][j] = (int)(100*Math.random());
}
}
我想你还没有初始化大小的表[i] [j]? – kosa