我有这个代码当我试图检查数组的大小时,我在最后一行得到NullPointerException错误但是请注意数组是在前一行中定义的任何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);
我收到此错误我试图检查网络上的解决方案,但我无法找到解决方案
Exception in thread "main" java.lang.NullPointerException
答案 0 :(得分:0)
静态类中的变量也应声明为静态