0

This question already has answers here:

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

So, I get this Error when run the bellow block code:

Error Message:

  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;
    }

How should I fix the NumberFormatException, When I run the above code I get NumberFormatException Error. Thanks in advance for your helping.

Ali Mosavi
  • 23
  • 5
  • 1
    That is not the code that is causing the exception, because the stack trace shows `Double.parseDouble` which you do not call anywhere in the code snippet you posted. Could you post the content of `PowerVmAllocationPolicyMigrationLocalRegression.isHostOverUtilized`? – Joachim Sauer May 05 '20 at 15:36
  • can you show the part where you are calling `Double.parseDouble`? Going by the Stacktrace it looks like you are trying to parse an array of doubles as a number, instead of parsing every element of the array itself to a number. – OH GOD SPIDERS May 05 '20 at 15:37

2 Answers2

0
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)

What this tells us is that the method isHostOverUtilized tried to pass the string [D@548b7f67 to Double.parseDouble. [D@548b7f67 is not at all a valid double value, so it throws an exception.

What seems to have happened is that isHostOverUtilized (or some related method) took a double[] instance, called .toString() on it (which results in the string [D@<some garbage value here>) and passed it as-is to Double.parseDouble.

BambooleanLogic
  • 7,530
  • 3
  • 30
  • 56
0

You have for some reason passed in the result of toString() of an array of doubles which is not a valid number. This may happen in a string concatenation.

You probably wanted the result of length instead.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347