mardi 12 mars 2019

Error : The type of the expression must be an array type but it resolved to int

I have a problem to convert from int to int []. I have tried to modify the coding but still have error. I want to change the method getRandomNumberInRange into int[] because i need to combine with [hostType] and [hostType] is in array form.

// this method is to convert from int to int[]
static Integer[] toObject(int[] intArray) {

                Integer[] result = new Integer[intArray.length];
                for (int i = 0; i < intArray.length; i++) {
                        result[i] = Integer.valueOf(intArray[i]);
                }
                return result;
        }
// this method to generate random number
public static int getRandomNumberInRange(int min, int max) {

                if (min >= max) {
                        throw new IllegalArgumentException("max must be greater than min");
                }

                Random r = new Random();
                return r.nextInt((max - min) + 1) + min;
        }
//this method is to implement the function getRandomNumberInRange and need to be in array form
public static List<PowerHost> createHostList(int hostsNumber) {
                List<PowerHost> hostList = new ArrayList<PowerHost>();
                for (int i = 0; i < hostsNumber; i++) {
                        int hostType = i % Constants.HOST_TYPES;

//                      int mips2[]=(int) getRandomNumberInRange(100, 1000);
                        List<Pe> peList = new ArrayList<Pe>();
                        for (int j = 0; j < Constants.HOST_PES[hostType]; j++) {
                                int[] obj = new int[hostType] ;
                                Integer[] newObj = toObject(obj);
                                peList.add(new Pe(j, new PeProvisionerSimple(getRandomNumberInRange(100, 1000)[newObj])));
                        }



Aucun commentaire:

Enregistrer un commentaire