键入将数字转换为双精度
我正在尝试为我的项目计算一些计算,我得到了关注java.lang.ClassCastException
y2= (double) molWt[x];
molWt
并且是两个类型为 Number 和 的数组。dist
double
java.lang.ClassCastException: java.lang.Integer 不能 cast to java.lang.Double
public Double calcData(Number[] molWt, Double[] dist, String unk) {
Double y2,y1, newY = null;
Double x1,x2;
Double unkn = Double.parseDouble(unk.toString());
Double prev=0d;
Double slope;
for (int x = 0; x < dist.length; x++)
if (unkn > prev && unkn < dist[x]) {
y2 = (double) molWt[x];
y1 = (double) molWt[x - 1];
x2 = dist[x];
x1 = dist[x - 1];
slope = ((y2 - y1) / (x2 - x1));
newY = slope * (unkn - x1) + y1;
} else {
prev = dist[x];
}
return newY;
}