You have an infinite loop when i < 2^30.
static int nextOne(int theInt) {
int answer = 1;
while (answer < theInt && 0 < answer) {
answer <<= 1;
}
if (answer < 1) {
throw new IllegalArgumentException("Sorry, " +
theInt + " is bigger than 2 to the power of 30 (1073741824).");
}
return answer;
}