I have this Code I am getting NullPointerException error at the last line when I tried to check the size of the array but please note that the array is defined in the previous line any suggesstion?
`static class point {
double x;
double y;
double z;
}
static class problem {
int n;
point[] nodeptr;
}
static double att_distance(int i, int j)
{
Tsp.instance = new Tsp.problem();
instance.nodeptr = new Tsp.point[Input.General_Inputs.Num_Of_Ppes];
instance.nodeptr[i] = new Tsp.point();
instance.nodeptr[i].x = InOut.General_Calculation.P_C[i];
instance.nodeptr[i].y = InOut.General_Calculation.C[i];
instance.nodeptr[i].z = InOut.General_Calculation.L[i];
instance.nodeptr[j] = new Tsp.point();
instance.nodeptr[j].x = InOut.General_Calculation.P_C[j];
instance.nodeptr[j].y = InOut.General_Calculation.C[j];
instance.nodeptr[j].z = InOut.General_Calculation.L[j];
double xd = (instance.nodeptr[i].x + 0.6*instance.nodeptr[i].y)*Math.pow(instance.nodeptr[i].z,-1);
double yd = (instance.nodeptr[j].x + 0.6*instance.nodeptr[j].y)*Math.pow(instance.nodeptr[j].z,-1);
double rij = ((xd + yd));
return rij;
}
static double[][] compute_distances()
{
int i, j;
double matrix[][] = new double[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
matrix[i][j] = att_distance(i, j);
}
}
return matrix;
}
static problem instance;
static int n=Input.General_Inputs.Num_Pipes_Selected-1;
Tsp.instance.distance = Tsp.compute_distances();
System.out.println("Tsp.instance.distance.length "+Tsp.instance.distance.length);
I get this error I tried to check on a solution on the net but I couldn't find a solution
Exception in thread "main" java.lang.NullPointerException