Have you ever encountered the error message, java.Lang.ArrayIndexOutOfBoundsException: index -1 out of bounds for length 2048, at the same time…