我最初想說,感謝您花時間看我的文章。基本上我試圖用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