Sorry for that.
This time I use an IDE and I found a silly bug.

Change this part:
Random generator = new Random();
int pos = generator.nextInt(A.length);
to this
Random generator = new Random();
int pos = generator.nextInt(countA);
I tested the method and it should work now.
