emory-courses / dsa-java

Data Structures and Algorithms in Java
https://emory.gitbook.io/dsa-java/
42 stars 55 forks source link

[HW#1] Null Pointer Exception #98

Closed lcunild closed 4 years ago

lcunild commented 4 years ago

I have tried implementing the improvement as discussed in office hours, however I am getting a null pointer exception (line 160) and I cannot figure out why.

https://github.com/lcunild/dsa-java/blob/master/src/main/java/edu/emory/cs/sort/hybrid/HybridSortHW.java

lujiaying commented 4 years ago

Null Pointer basically means you are trying to access some out-of-boudary index of certain arrays. Be really careful the index issues.

Please take a look at the error log. You can find in some certain line the index you dynamically access may be not valid.

lujiaying commented 4 years ago

More specifically, the bug is introduced by L160.

lcunild commented 4 years ago

I think I have worked out why I was getting the null pointer exception, however now the exception I am getting is java.lang.ClassCastException: : class [[Ljava.lang.Integer; cannot be cast to class [Ljava.lang.Comparable. I do not get this error if I try to create a copy of the array in my main method, only when I try to do it in the merge method.

lcunild commented 4 years ago

I have sorted it, thank you for your help!