title: can't do getNextSibling() because of null
body: <p>i am traversing an xml tree using java..right now i am having trouble in getting the node's sibling using node.getPreviousSibling(),here is the code :</p>
  
  <pre><code>sibling = pointer.getPreviousSibling();
  while (sibling==null){
                      System.out.println("YAAAAAA");
  
                      sibling = sibling.getPreviousSibling(); ///here is the error occured
                  }
  </code></pre>
  
  <p>the error was NullPointerException.
  i know that getPreviousSibling() could return null if there is no sibling..
  the question is : </p>
  
  <ol>
  <li>why sibling.getPreviousSibling() gave me an error instead of assign the null value into test Node without giving me an exception?</li>
  <li>what should i do so that my code will run just fine even if it's looping forever because the sibling will always null?</li>
  </ol>
  
  <p>thank you..</p>
  
  <p>EDIT 1 : before the code above,i already checked if the pointer is null or not</p>
  
  <pre><code>if(pointer==null){
  System.out.println("NULL");
  }
  </code></pre>
  
  <p>but still,it shows that the pointer wasn't a null..
  so i wonder what triggers the NullPointerException</p>
  
  <p>EDIT 2 : i figured another way,and it seems that i make mistake somehow when assigning the pointer (not sure which one is the mistake, but i'm sure there is a mistake)
  my new way is by getting the node parent using </p>
  
  <pre><code>Node parent =pointer.getParentNode();
  </code></pre>
  
  <p>from there i choose which child that i want..</p>
  
  <p>thanks to @almas and @demostene for pointing out i'm calling getPreviousSibling the wrong way </p>