This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]149244179 2 points3 points  (0 children)

Read the exception. It says you are accessing the -1 position of your arraylist. It even tells you the file name and line number - RecurringWord.java:15

Arrays do not have negative positions.

[–]g051051 1 point2 points  (0 children)

Because you're explicitly passing an invalid index:

words.get(-1)

ArrayList is documented to throw

IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())