I'm working on a program using eclipse that generates objects for runners in a 100 m race. each runner has a lane, name and three separate times for completing the race. However, when I try to generate the times for each object, I get java.lang.NullpointerException.
Here is the method for generating the times.
public double[] getTimes() {
for (int i = 0; i <= (times.length - 1); i++) {
rolled = 1.0 + roll.nextDouble() * 100.0;
// set rolled to a new random number between 1 and 100
times[i] = rolled;
// set index i of the array times to be the nearest
// double to roll's value.
}
return times;
}
and then the code in which the method is called.
public void testGetTimes() {
double[] times = performance.getTimes();
assertEquals(2, times.length);
assertEquals(9.2, times[0], 0.01);
assertEquals(9.4, times[1], 0.01);
}
I'd try to fix it through debugger, but every time i try to step-into the for loop, i get InvocationTargetException,(Throwable line: not available
initialization of times, roll and rolled:
public class Performance {
private int lane;
private String name;
double[] times = new double[3];
int rolling;
Random roll = new Random();
double rolled;
double average;
double best;
and of performance:
public class PerformanceTest {
Performance performance;
@Before
public void setup() {
performance = new Performance(1, "", new double[]{9.2, 9.4});
}