0

While i am running this array to sort values in descending order..

Double p[] = new Double[25];
for (int i = 0; i < size; i++) {
    gridlet = (Gridlet) list.get(i);
    p[t] = gridlet.getActualCPUTime();
    t++;
    Arrays.sort(p);
    Arrays.sort(p, Collections.reverseOrder());
    System.out.print(p[i]);
}

It gives these errors..

java.lang.NullPointerException
    at java.util.ComparableTimSort.countRunAndMakeAscending(Unknown Source)
    at java.util.ComparableTimSort.sort(Unknown Source)
    at java.util.Arrays.sort(Unknown Source)
    at GridExp.MaxMin.printGridletList(MaxMin.java:460)
    at GridExp.MaxMin.main(MaxMin.java:299)

Please help me with this..

Ben Green
  • 3,953
  • 3
  • 29
  • 49
Sophiya
  • 13
  • 3
  • 2
    You might want to finish populating the array before sorting it. (move `Arrays.sort(p); Arrays.sort(p,Collections.reverseOrder());` outside the loop). – Eran Sep 12 '16 at 08:05
  • And with regard to your title, unrelated to the issue, refer to http://stackoverflow.com/questions/1694751/java-array-sort-descending – Tunaki Sep 12 '16 at 08:06
  • also [http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) for your actual problem – SomeJavaGuy Sep 12 '16 at 08:10
  • @Tunaki Please see my code once..I am having different issues..not able to resolve these. Thank You. – Sophiya Sep 12 '16 at 08:15
  • @Eran outside the loop i can not get gridlet parameter – Sophiya Sep 12 '16 at 08:17
  • @Sophiya as `gridlet` seems to not be defined in the loop i doubt that you can´t – SomeJavaGuy Sep 12 '16 at 08:18
  • You are getting am NPE because you are attempting to sort the array after adding just one element and all the other elements are `null`. You should attempt to sort the array only after adding all the elements. You can use your debugger to step through the code to see what you are doing wrong. I also suggest using your IDE to format your code as it will help find bugs like this. – Peter Lawrey Sep 12 '16 at 08:51

0 Answers0