Bug 607 - Accessing index 0 of an empty array list
Summary: Accessing index 0 of an empty array list
Status: RESOLVED FIXED
Alias: None
Product: Group14-Pacman
Classification: Unclassified
Component: Game (show other bugs)
Version: 0.0.2
Hardware: PC Windows
: High enhancement
Assignee: Aleksa
URL:
Depends on:
Blocks:
 
Reported: 2021-11-24 15:48 HKT by Aleksa
Modified: 2021-12-06 00:15 HKT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aleksa 2021-11-24 15:48:06 HKT
I ran Main.java with the initial mode to be "Frightened". Then I provided my name and difficulty to the program. Moreover, I input "Left" for Pacman to got left. I expected to see a maze in which Pacman moved to the left on the console, but instead, this was the output:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
	at java.base/java.util.Objects.checkIndex(Objects.java:359)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at Game.Game.moveGhosts(Game.java:244)
	at Game.Game.handleMovements(Game.java:165)
	at Game.Game.gameTick(Game.java:83)
	at Game.Main.main(Main.java:55)
Comment 1 Aleksa 2021-11-24 15:51:17 HKT
Solution:

ArrayList of algs in Frightened.java is not null when retrieved to Game.java. I changed to checking condition in boolean moveGhosts() in Game.java from if(algs!=null)  to  if (algs.size()!=0)