gpt4 book ai didi

java - IndexOutofBoundException 为什么?

转载 作者:行者123 更新时间:2023-12-01 19:07:07 25 4
gpt4 key购买 nike

我遇到了一个小问题,我收到错误 java.lang.IndexOutOfBoundsException: Index: 29, Size: 29 当我启动此代码时,错误位于行 if ((listaSwiat != null && listaSwiat.get(x) != null) || Harm.get(y).getDzienTygodnia(x + 1).equals("Nd")) 但不知道为什么索引应该是 30 而不是 29any1 可以提供帮助吗?

for (int y = 0; y < harm.size(); y++) {//wiersze
c1 = new PdfPCell(new Phrase(harm.get(y).nazwa, stdFont));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("" + harm.get(y).getSumaGodzin() + " / " + harm.get(y).normaGodzin, smallFont));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
for (int x = 0; x < harm.get(y).dni.size(); x++) {//kolumny
c1 = new PdfPCell(new Phrase(harm.get(y).dni.get(x).godziny, smallFont));
//dla swiąt ustal kolor tła na czerwono
//dla niedziel ustala kolor tla na czerwony
if ((listaSwiat != null && listaSwiat.get(x) != null) || harm.get(y).getDzienTygodnia(x + 1).equals("Nd")) {
c1.setBackgroundColor(BaseColor.RED);
}

最佳答案

在 Java(以及许多其他编程语言)中,索引从零开始,而不是从一开始。

这意味着,如果大小为 29,则最后一个有效索引为 28,而不是 29。

关于java - IndexOutofBoundException 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9642772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com