我試圖將數組中的值設置爲變量。這裏是我的代碼:如何向數組添加變量
//init the array as a float
//I have tried to put a value in the brackets, but it returns a different error.
//I initialized it this way so I could call it from other methods
private float[] map;
// generate a "seed" for the array between 0 and 255
float x = generator.nextInt(256);
int n = 1;
// insert into the first 25 slots
while(n <= 25) {
// here's my problem with this next line
map[n] = x;
double y = generator.nextGaussian();
x = (float)Math.ceil(y);
n = n + 1;
}
我打上我的錯誤行,返回的錯誤是:「在拋出未捕獲的異常......」。我究竟做錯了什麼???提前致謝。
編輯-----
這裏是整個異常:
Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
我使用y以生成隨機高斯,則X轉換成float值,改變成浮動值
我很確定這是這條線,因爲這是我的編譯器告訴我的。
你能發佈更多的異常。你還可以展示如何定義地圖? – Gray
什麼是'map'? 'y'是什麼? – juliomalegria
「地圖」的類型是什麼?錯誤的全部信息是什麼?可能不是下一行? (generator.nextGaussian();) – DPM