Hello. I am in need of assistance for sorting an array of objects. I have two variables called "BallInfo infos" which holds the objects inside an array of BallInfo, and a another variable called "numOfInfos" that keeps track of the actual amount of objects inside the array:
So I am unsure why I am getting a NullPointerException for the following code below:
1 2 | infos = new BallInfo[ 43 ]; numOfInfos = 0 ; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public void sortByTotal() { boolean notSorted = true ; while (notSorted) { notSorted = false ; for ( int index= 0 ; index<numOfInfos; index++) { if (infos[index].getTotal() < infos[index+ 1 ].getTotal()) //I get the error on this line of code { swap(index, index+ 1 ); notSorted = true ; } } } } |