IndexOutOfBoundException 왜?
-
10-12-2019 - |
문제
필자는 작은 문제가 있습니다. java.lang.IndexoutOfBoundsException : 색인 : 29, 크기 : 29이 코드 오류가 발생할 때 if ((listaSwiat != null && listaSwiat.get(x) != null) || harm.get(y).getDzienTygodnia(x + 1).equals("Nd"))
라인이지만 Dunno 왜 INDER 30 ANY1은 도움이되지 않습니다.
해결책
It looks like you are looping over all the elements of harm.get(y).dni and inside the loop you do
if ((listaSwiat != null && listaSwiat.get(x) != null)
|| harm.get(y).getDzienTygodnia(x + 1).equals("Nd"))
The last time through the loop x = 28 and the size is 29. But you do
harm.get(y).getDzienTygodnia(x + 1)
So you get the element at spot 29 which is out of bounds, because like the other answer stated the index starts at 0 not 1. You have to add a check here to see if you are currently at the last index before checking the next index.
다른 팁
In Java (and many other programming languages), indices start at zero, not one.
This means that, if the size is 29, the last valid index is 28, not 29.
Break apart the line that causes the exception so you can see exactly which call to get
is failing.
boolean listaSwiatCheck = listaSwiat != null && listaSwiat.get(x) != null;
if (listaSwiatCheck || harm.get(y).getDzienTygodnia(x + 1).equals("Nd")) {
c1.setBackgroundColor(BaseColor.RED);
}