I\'m working on my assignment and I am suppose to create a sort method for my array. However, I\'m getting a null pointer error in my sort method and I\'m not sure why. This is
The cause of NPE is that you store null in your array. The implementation of ComparableTimSort does not check for null.
private static void binarySort(Object[] a, int lo, int hi, int start) {
214 assert lo <= start && start <= hi;
215 if (start == lo)
216 start++;
217 for ( ; start < hi; start++) {
218 @SuppressWarnings("unchecked")
219 Comparable
You must assure that null value is not stored in your array.
To do that you must assert that argument passed in method add
is not null and create a copy of your container before sorting to valid size.
public Object[] sorted() {
Object[] toSort = Arrays.copyOf(getSetArray(),getSize());
Arrays.sort(toSort);
return toSort;
}