我试图将数组中的值设置为变量。这里是我的代码:如何向数组添加变量
//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