英文:
Index out of bounds, but I have no idea where
问题
以下是你的代码片段,已经翻译好的部分:
这些是我的代码片段,但我一直在收到相同的错误,而且我不知道为什么。
我一直收到
异常信息:"main"线程中的java.lang.ArrayIndexOutOfBoundsException: 下标 2 超出长度 2
位于 Grammar.
我可以看出这与数组大小有关,也许,但我不知道具体在哪里。
提前感谢任何能帮助我的人,将不胜感激。
public int getInit() {
return init;
}
int max = 100;
int[][] ntr = new int[max][0];
NTR tempo = nttemp.remove(0); // NTR 是另一个仅包含 getter 方法的类
int tempoF = tempo.getFirst();
int tempoS = tempo.getSecond();
int i = 1;
92 ntr[tempo.getInit() - 'A'][i] = tempoF;
i++;
ntr[tempo.getInit() - 'A'][i] = tempoS;
i++;
英文:
These are snippets of my code, but I keep getting the same error and I have no idea why.
I keep getting
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
at Grammar.<init>(Grammar.java:92)
I can see that it has to do with the array size, maybe, but I have no idea where.
Thank you in advance if someone can help me, it would be greatly appreciated.
public int getInit() {
return init;
}
int max = 100;
int[][] ntr = new int[max][0];
NTR tempo = nttemp.remove(0); // NTR is another class that contains only gets
int tempoF = tempo.getFirst();
int tempoS = tempo.getSecond();
int i = 1;
92 ntr[tempo.getInit() - 'A'][i] = tempoF;
i++;
ntr[tempo.getInit() - 'A'][i] = tempoS;
i++;
答案1
得分: 1
你创建了一个大小为零的数组组。每当您尝试对其进行下标引用时,由于零长度数组没有有效的索引(无论类型如何),它都将超出范围。
英文:
You create a zero sized array of arrays. Whenever you try to subscript that, it will be out of bounds since there are no valid indices for a zero length array (whatever the type).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论