title: get element from an index in a linked list
body: <p>I'm writing my own LinkedList class (i know there is one in the API .. etc) I have integers stored in my DLink and getElement() returns the integer stored in the link.</p>
  
  <p>I am getting a null pointer exception from the line "return temp.getElement();" is there something wrong with my get method? e.g of why I want this method: when I call get(0) I want to return the first element in the list</p>
  
  <pre><code>public int get(int index)
  {
  
         //forces the index to be valid
        assert (index &gt;= 0 &amp;&amp; index &lt; size());
  
        DLink temp = _firstLink; //start at the head of the list
  
        //iterate to the correct node
        for(int i = 0; i &lt; index; i++)
        {
            temp = temp._next;
        }
  
        return temp.getElement(); //and return the corresponding element
  
  
  
      }
  </code></pre>
  
  <p>here is my DLink class if you want to look at it:</p>
  
  <pre><code>//elements in DLink are integers
  public class DLink {
      public int _element;
  
      public DLink _next;
      public DLink _previous;
  
      public DLink(int e)
      {
          _next = null;
          _previous = null;
  
          this._element = e;
      }
  
      public int getElement()
      {
          return _element;
      }
  
      public void setNext(DLink link)
      {
          _next = link;
      }
      public void setPrev(DLink link)
      {
          _previous = link;
      }
  
      public DLink getPrev()
      {
          return _previous;
      }
  
      public DLink getNext()
      {
          return _next;
      }
  
  }
  </code></pre>