gpt4 book ai didi

java - 如何修复它,NumberFormatException : For input string: "[D@548b7f67"

转载 作者:行者123 更新时间:2023-12-01 16:54:28 25 4
gpt4 key购买 nike

这个问题已经有答案了:

java.lang.NumberFormatException: For input string: “0.000” [duplicate]

因此,运行以下 block 代码时出现此错误:

错误消息:

  java.lang.NumberFormatException: For input string: "[D@548b7f67"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at org.cloudbus.cloudsim.power.PowerVmAllocationPolicyMigrationLocalRegression.isHostOverUtilized(PowerVmAllocationPolicyMigrationLocalRegression.java:169)
at org.cloudbus.cloudsim.power.PowerVmAllocationPolicyMigrationAbstract.getOverUtilizedHosts(PowerVmAllocationPolicyMigrationAbstract.java:397)
at org.cloudbus.cloudsim.power.PowerVmAllocationPolicyMigrationAbstract.optimizeAllocation(PowerVmAllocationPolicyMigrationAbstract.java:96)
at org.cloudbus.cloudsim.power.PowerDatacenter.updateCloudletProcessing(PowerDatacenter.java:102)


**My Code:**

@Override
protected boolean isHostOverUtilized(PowerHost host) {

PowerHostUtilizationHistory _host = (PowerHostUtilizationHistory) host;

double[] utilizationHistory = _host.getUtilizationHistory();
double[] ramUtilizationHistory = _host.getRamUtilizationHistory();
double[] bwUtilizationHistory = _host.getBWUtilizationHistory();

final List<double[]> utiLizationList = Arrays.asList(utilizationHistory,
ramUtilizationHistory, bwUtilizationHistory);
double x[][] = new double[utilizationHistory.length][3];

for(int i = 0; i< utilizationHistory.length;i++)
{
for(int j=0; j<utiLizationList.size(); j++){
x[i][j] = utiLizationList.get(j)[i];
//System.out.print(" "+ x[i][j] +"");
}
//System.out.println();
}


double[] y = new double[utilizationHistory.length];

for(int i=0; i<utilizationHistory.length; i++)
{
y[i] =
(double) utilizationHistory[i]/1-(double)
utilizationHistory[i] *
(double) ramUtilizationHistory[i]/1-(double) ramUtilizationHistory[i] *
(double) bwUtilizationHistory[i]/1-(double) bwUtilizationHistory[i] ;
}

for(int i=0; i<utilizationHistory.length; i++)
{
//Log.printLine(" "+ y[i]);
}

int length = 10; // we use 10 to make the regression responsive enough to latest values
if (utilizationHistory.length < length) {
return getFallbackVmAllocationPolicy().isHostOverUtilized(host);
}

double[] utilizationHistoryReversed = new double[length];
for (int i = 0; i < length; i++) {
utilizationHistoryReversed[i] = utilizationHistory[length - i - 1];
}

OLSMultipleLinearRegression regression = null;
try {
regression = getParameterEstimates(x, y);
} catch (IllegalArgumentException e) {
return getFallbackVmAllocationPolicy().isHostOverUtilized(host);
}

double[] estimates = regression.estimateRegressionParameters();

for(int i=0; i<estimates.length; i++)
{
Log.printLine("estimates ______ "+ estimates[i]);
}


// System.exit(0);

// double migrationIntervals = Math.ceil(getMaximumVmMigrationTime(_host) / getSchedulingInterval());
//double predictedUtilization = estimates[0] + estimates[1] * (length + migrationIntervals);

double predictedUtilization = 0;

for(int i=0; i<utilizationHistory.length; i++)
{
predictedUtilization = estimates[0] +
(estimates[1] * utilizationHistory[i]) +
(estimates[2] * ramUtilizationHistory[i])+
(estimates[3] * bwUtilizationHistory[i]);
}

Log.printLine("___________predictedUtilization: " + predictedUtilization);

predictedUtilization *= getSafetyParameter();

addHistoryEntry(host, predictedUtilization);

return predictedUtilization >= 1;
}

我应该如何修复 NumberFormatException,当我运行上面的代码时,我收到 NumberFormatException 错误。预先感谢您的帮助。

最佳答案

java.lang.NumberFormatException: For input string: "[D@548b7f67"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at org.cloudbus.cloudsim.power.PowerVmAllocationPolicyMigrationLocalRegression.isHostOverUtilized(PowerVmAllocationPolicyMigrationLocalRegression.java:169)

这告诉我们方法 isHostOverUtilized试图传递字符串 [D@548b7f67Double.parseDouble[D@548b7f67根本不是有效的 double 值,因此它会引发异常。

似乎发生的事情是isHostOverUtilized (或一些相关的方法)采取了 double[]实例,名为 .toString()其上(产生字符串 [D@<some garbage value here> )并将其按原样传递给 Double.parseDouble .

关于java - 如何修复它,NumberFormatException : For input string: "[D@548b7f67",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61616820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com