Carly Griffin wrote:Hi, I'm writing the add(int position, T data) method for a doublyLinkedList. I'm attempting to use the method but am generating a NullPointerException error when I attempt to add to the end of a list.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Carly Griffin wrote:Hi, I'm writing the add(int position, T data) method for a doublyLinkedList. I'm attempting to use the method but am generating a NullPointerException error when I attempt to add to the end of a list.
For example, I am trying to do:
and I'm receiving an error for test.add(1,2).
Here is my code for my add method:
I am tracing the error back to the line in the else loop:
but I can't figure out what is causing this.
Thank you in advance for your help!
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Campbell Ritchie wrote:You are right to throw that sort of Exception. Far better than letting it find a null and throw a null exception (=NPE).
Carly Griffin wrote:...I'm just doing this according to how I was instructed...
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |