I wrote a function:
private static LinearFunction[] aproxFunction(List<Point> list) {
try{
int amountOfClusters = getAmountOfClusters(list);
//System.out.println(amountOfClusters); for debug
LinearFunction[] linear = new LinearFunction[amountOfClusters];
int[][] clusters = new int[amountOfClusters][2]; // 2nd field 0 == r, 1 == g, 2 == b
clusters = getClusters(list, amountOfClusters);
for(int i = 0; i < amountOfClusters; i++) {
List<Point> pointsList = new ArrayList<>(getPointsInCluster(list, clusters[i][0], convertIdToString(clusters[i][1])));
int[][] points = new int[pointsList.size()][3];
for(int j = 0; j < points.length; j++) {
points[j][0] = pointsList.get(j).getX();
points[j][1] = pointsList.get(j).getY();
points[j][2] = pointsList.get(j).getValue();
}
pointsToFile(pointsList, clusters[i][0], convertIdToString(clusters[i][1]), "_points_in_cluster_");
int[][] array = new int[2][2];
array = aprox(removeDuplicates(points));
if((array[1][0] - array[0][0]) == 0) {
linear[i].a = 0;
linear[i].b = 0;
linear[i].flag = true;
linear[i].c = array[0][0];
} else {
linear[i].a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
linear[i].b = array[1][1] - array[1][0] * linear[i].a;
}
linear[i].cluster = clusters[i][0];
linear[i].id = convertIdToString(clusters[i][1]);
}
return linear;
} catch (Exception e) {
System.out.println("Error - aproxFunction: " + e.getMessage());
}
LinearFunction[] error = new LinearFunction[1];
error[0].a = -1;
return error;
}
and I constantly receive the error messages of either division by null
or just null
. I can't find the reason for that.
The only division in this function happens here:
linear[i].a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
but above that you have a check for null division, so how can I still get that error message.
As for the error message null
I just don't know what it means. I read that it might be caused by an objects being null but how to find out which and where?