IndexOutOfBounds与阵列 [英] IndexOutOfBounds with array

查看:142
本文介绍了IndexOutOfBounds与阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我尝试运行这个方法

Each time I try to run this method

private void resetOdds() {
    mOdds[1] = 0.10;
    mOdds[2] = 0.25;
    mOdds[3] = 0.35;
    mOdds[4] = 0.30;
}

我得到一个IndexOutOfBounds错误。我不知道为什么,因为我提供足够的项目数组中的改变:

I get an IndexOutOfBounds error. I don't know why, as I supply enough items in the array to change:

private final double[]      mOdds           = { 0.10, 0.25, 0.30, 0.35 };

有谁知道为什么我收到这个错误?

Does anyone know why I'm getting this error?

推荐答案

您的索引是关闭的之一;它应该从0开始:

Your indexing is off by one; it should start at 0:

mOdds[0] = 0.10;
mOdds[1] = 0.25;
mOdds[2] = 0.35;
mOdds[3] = 0.30;

这篇关于IndexOutOfBounds与阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆