Could You tell me whether i can create multidimensional array which is created with my objects in java?
In other words:
I have got this class:
public class ClosestObject {
public Double distance;
public String classes;
public ClosestObject() {
this.distance=new Double(0);
this.classes=new String("");
// TODO Auto-generated constructor stub
}
}
And I want to create multidimensional array in another class in that way:
ClosestObject[][] closestobj=new ClosestObject[query.length][learning_set.length];
for(int i=0; i<query.length;i++)
{
for(int j=0;j<learning_set.length;j++)
{
closestobj[i][j].distance=Math.abs(query[i]-learning_set[j][0]);
closestobj[i][j].classes=classes[j][0];
}
}
for(int i=0;i<closestobj.length;i++)
{
for(int j=0;j<closestobj[i].length;j++)
{
System.out.println(closestobj[i][j].distance + " " + closestobj[i][j].classes);
}
}
Unfortunatelly I get this error:
Exception in thread "main" java.lang.NullPointerException
at KNN.Find_closest_distance(KNN.java:60)
at KNN.main(KNN.java:37)
Could someone tell me where i made mistake. Thank You in advance :)