I think the solution is correct, but it's giving run error when I submit

import java.util.*;
public class Main {
private static final Boolean [] isPrime = new Boolean[1000001];
private static final int [] totalCost = new int[10001];
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
fillCache();
totalCost();
while(n-- > 0){
System.out.println(totalCost[in.nextInt()]);
}
}

private static void fillCache(){
    for(int i = 0 ; i < isPrime.length ; i++){
        isPrime[i] = true;
    }
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i = 2 ; i*i < isPrime.length ; i++){
        if(isPrime[i]){
            for(int j = i*i ; j < isPrime.length ; j=j+i){
                isPrime[j] = false;
            }
        }
    }
}

private static void totalCost(){
    int i = 0;
    int primeCounts = 0;
    while(primeCounts < totalCost.length - 1){
        i++;
        if(isPrime[i]){
            primeCounts++;
            totalCost[primeCounts] = i;
        }
    }
}

}

I hate this iterface