I am guessing line 27 is this one:
You get an ArrayIndexOutOfBoundsException when you try and access an array with a negative index, or one >= the length of the array. Remember that array indices start at zero and go to length-1. You can test whether you are doing this here by inserting a System.out.println():
System.out.println("BUTTON has length " + BUTTON.length);
System.out.println("About to access BUTTON[i] where i=" + i);
PRIME.add(BUTTON[i]);
-----
It would be good if you followed Java coding conventions and used lowercase letters for packages and variables. This adds readability.
In terms of the logic of your code it you should remove any use of "static" other than for main(). And declare variables close to where you use them. In this case the int
i might better be declared as part of the for loop rather than as a static class variable. (Of course both of these things may involve addressing problems to which the compiler alerts you. But, often, problems are made worse, not better, if the compiler is made to shut up by making variables static and/or giving them excessive scope.)