Hi everyone , I am getting
" Exception in thread "main" java.lang.ClassCastException " error
when I run the following code:
private float[][] getDistancesTable(LinkedList Betas, byte metrics) {
Beta_Sheet b1 = new Beta_Sheet();
Beta_Sheet b2 = new Beta_Sheet();
b1 = null;
b2 = null;
int betacount = Betas.size(); //the size of the array
// System.out.println("the metrics is" + metrics);
float[][] distances = new float[betacount][betacount]; //two dimentional array
//Beta_Sheet[] bs = (Beta_Sheet[]) Betas.toArray(new Beta_Sheet[betacount]); //creates an 3 dimentional array of betas
//System.out.println("the length of the array is" + bs.length);
// TODO check if the table is already in the database
for (int i = 0; i < betacount; i++) {
//b1 = bs;
b1 = (Beta_Sheet)Betas.get(i); //
System.out.println(" I am still here");
b1 =(Beta_Sheet) Betas.get(i);
for (int j = i + 1; j < betacount; j++) {
//b2 = bs[j];
b2 = (Beta_Sheet)Betas.get(j);
switch (metrics) {
case _AVERAGE_DISTANCE_REF:
distances[j] = b1.DistanceWithBeta(b2);
break;
case _GPOINT_DISTANCE:
distances[j] = b1.DistanceToCentre(b2);
break;
case _MIN_DISTANCE:
System.out.println("i'm in the minimum distance option");
distances[j] = b1.MinimumDistance(b2);
break;
case _AVERAGE_DISTANCE:
distances[j] = b1.Distancetobeta(b2);
break;
default:
// do nothing
break;
}
}
}
return distances;
}
Exact Error is:
Exception in thread "main" java.lang.ClassCastException: java.lang.String
at JFILES.BetaNeighboursFinder.getDistancesTable(BetaNeighboursFinder.java:82)
at JFILES.BetaNeighboursFinder.main(BetaNeighboursFinder.java:131).
I think the error is at this line:
b1 = (Beta_Sheet)Betas.get(i); //
But I seriously don't know how to solve it, your help is really appreciated
Best regards,
Zia
" Exception in thread "main" java.lang.ClassCastException " error
when I run the following code:
private float[][] getDistancesTable(LinkedList Betas, byte metrics) {
Beta_Sheet b1 = new Beta_Sheet();
Beta_Sheet b2 = new Beta_Sheet();
b1 = null;
b2 = null;
int betacount = Betas.size(); //the size of the array
// System.out.println("the metrics is" + metrics);
float[][] distances = new float[betacount][betacount]; //two dimentional array
//Beta_Sheet[] bs = (Beta_Sheet[]) Betas.toArray(new Beta_Sheet[betacount]); //creates an 3 dimentional array of betas
//System.out.println("the length of the array is" + bs.length);
// TODO check if the table is already in the database
for (int i = 0; i < betacount; i++) {
//b1 = bs;
b1 = (Beta_Sheet)Betas.get(i); //
System.out.println(" I am still here");
b1 =(Beta_Sheet) Betas.get(i);
for (int j = i + 1; j < betacount; j++) {
//b2 = bs[j];
b2 = (Beta_Sheet)Betas.get(j);
switch (metrics) {
case _AVERAGE_DISTANCE_REF:
distances[j] = b1.DistanceWithBeta(b2);
break;
case _GPOINT_DISTANCE:
distances[j] = b1.DistanceToCentre(b2);
break;
case _MIN_DISTANCE:
System.out.println("i'm in the minimum distance option");
distances[j] = b1.MinimumDistance(b2);
break;
case _AVERAGE_DISTANCE:
distances[j] = b1.Distancetobeta(b2);
break;
default:
// do nothing
break;
}
}
}
return distances;
}
Exact Error is:
Exception in thread "main" java.lang.ClassCastException: java.lang.String
at JFILES.BetaNeighboursFinder.getDistancesTable(BetaNeighboursFinder.java:82)
at JFILES.BetaNeighboursFinder.main(BetaNeighboursFinder.java:131).
I think the error is at this line:
b1 = (Beta_Sheet)Betas.get(i); //
But I seriously don't know how to solve it, your help is really appreciated
Best regards,
Zia