Question

Am I just to blind to see the solution?

sampleSum = 0;
for(int x : sampleWeights)
   sampleSum += x;

population = new int[sampleSum];
int z = 0;

for(int i = 0; i < nsamples; i++)
for(int j = 0; j < sampleWeights[i]; j++) 
{
    population[z] = i;
    z++;
}  

Any help is appreciated! Thanks!

Was it helpful?

Solution

If all sampleWeights is zero sampleSum will be zero and population.length=0. So when you do population[z] there will be an ArrayIndexOutOfBoundsException.

OTHER TIPS

I presume that you have N integers, N = # Samples x # weights/Sample(i)?

If this is the case, from where did you get the sampleWeights array (or List given autoboxing of Integers)?

Run your code again with some System.out.println's to gather debug info, and you'll quickly see what's wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top