Fixing java.lang.IndexOutOfBoundsException after Game Ends
Posted: Mon Mar 04, 2024 12:53 am
Every time I play a match, the statistics screen remains visible for an extended time post-match, and then the game experiences a crash with error:
so I have updated the
The following outlines the stack trace resulting from the crash.
The following outline the logging output after implementation the Fix, and playing two games:
Code: Select all
java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0
com.ygames.ysoccer.competitions.Compitiation.getTeam
Code: Select all
public Team getTeam(int side) {
int teamIndex = getTeamIndex(side);
// Added the following checks to Fix
// java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0
if(teams == null || teams.size() <= teamIndex || teamIndex < 0) {
Gdx.app.error("Team", "No valide team index found; Team not found <teamIndex=" + teamIndex + ", teams.size =" + teams.size() + ">");
return null;
}
// End Checks
return teams.get(teamIndex);
}
Code: Select all
$ gradlew desktop:run
> Task :desktop:run
[Controllers] added manager for application, 1 managers active
java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
at java.base/java.util.Objects.checkIndex(Objects.java:385)
at java.base/java.util.ArrayList.get(ArrayList.java:427)
at com.ygames.ysoccer.competitions.Competition.getTeam(Competition.java:188)
at com.ygames.ysoccer.competitions.Competition.dropSuspensions(Competition.java:475)
at com.ygames.ysoccer.competitions.Competition.matchCompleted(Competition.java:425)
at com.ygames.ysoccer.screens.MatchScreen.quit(MatchScreen.java:115)
at com.ygames.ysoccer.screens.MatchScreen.access$000(MatchScreen.java:20)
at com.ygames.ysoccer.screens.MatchScreen$1.quitMatch(MatchScreen.java:43)
at com.ygames.ysoccer.match.Match.quit(Match.java:615)
at com.ygames.ysoccer.match.MatchState.quitMatch(MatchState.java:88)
at com.ygames.ysoccer.match.MatchStateEnd.checkConditions(MatchStateEnd.java:67)
at com.ygames.ysoccer.match.SceneFsm.think(SceneFsm.java:127)
at com.ygames.ysoccer.match.Scene.update(Scene.java:24)
at com.ygames.ysoccer.match.Match.update(Match.java:40)
at com.ygames.ysoccer.screens.MatchScreen.render(MatchScreen.java:67)
at com.ygames.ysoccer.framework.GLGame.render(GLGame.java:146)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:232)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:127)
$ gradlew desktop:run
> Task : desktop:run
[Controllers] added manager for application, 1 managers active
[Team] No valide team index found; Team not found <teamIndex=-1, teams.size =0>
[Team] No valide team index found; Team not found <teamIndex=-1, teams.size =0>
[Team] No valide team index found; Team not found <teamIndex=-1, teams.size =0>
[Team] No valide team index found; Team not found <teamIndex=-1, teams.size =0>
[Controllers] removed manager for application, 0 managers active