【发布时间】:2011-11-22 23:26:56
【问题描述】:
我正在尝试将数组中的值设置为变量。这是我的代码:
//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 更改为该浮点值
我很确定就是那一行,因为这是我的编译器告诉我的。
【问题讨论】:
-
你能发布更多的例外情况吗?能否也说明一下地图是如何定义的?
-
什么是
map?y是干什么用的? -
“地图”的类型是什么?错误的全部信息是什么?可能不是下一行? (generator.nextGaussian();)
-
过于本地化。我怎么知道它太本地化了? 没有办法为这个问题写一个好的标题。 1) 读取异常,发布异常,以某种有意义的方式使用异常来解决问题 2) 发布所有适用的代码。此外,作为一个 nit,不可能将变量添加到数组 - 只能添加 values。
-
好吧,-1 是因为没有真正倾听 cmets 和更新问题。
标签: java arrays variables loops random