title: Getting nth node from a linked list
body: <p>I have these code:
  Class File:</p>
  
  <pre><code>public class LinkedListCustom&lt;T&gt; implements AbstractList&lt;E&gt;
  {
      private int numElements; private Node head, tail;
      ...
      ...
  
      public Node(T element)
      {
           T data; 
           Node next, prev;
      }
      ...
      ...
      private Node getNthElem(int index)
      {
          Node temp = head;
          for(int i=0; i&lt;index; i++)
          {
              temp = temp.next;
          }
          return temp;
      }
  
      public T getNthVal(int index)
      {
         Node n = getNthElem(index);
         return n.data;
      }
  
  }
  </code></pre>
  
  <p>Test file:</p>
  
  <pre><code>public class Tester extends TestCase
  {
      public void testGetN()
      {
          MyCustomLinkedList&lt;Integer&gt; myList = new MyCustomLinkedList&lt;Integer&gt;();
          myList.add(1);
          myList.add(2);
          assertEquals("index 0 is 1", new Integer(2), myList.getNthValue(1);
      }
  }
  </code></pre>
  
  <p>However, this does not run properly. May I know what I could have done wrongly? If there is anything unclear I'll clarify it immediately.</p>
  
  <p><strong>EDIT: It compiles but there is a NullPointerException.</strong></p>
  
  <p><strong>EDIT 2: <em>SOLVED</em> Sorry about the vague question and unclear code, but I just wanted to find out what I might not have implemented, and it turns out that @JaviFernandez was correct by asking whether I have implemented the add() method, which I didn't. I was just looking for an answer like that... Sorry if I have troubled anyone...</strong></p>