title: Cant print my last node in linked list
body: <p>Im doing a project that creates a linked list to form two polynomials, then gives the user the option to do math operations with the lists. I've gotten to the point where i'm reading my list in, and using stack to order it properly. Then I wanted to make sure my list was being read in properly and so far so good, EXCEPT my tail end isn't being read in. Or maybe its my syntax on my while loop?</p>
  
  <pre><code>import java.util.*;
  
  public class IntegerNode {
  
      private int coefficient;
      private int exponent;
      private IntegerNode next;
  
      public IntegerNode() {
          coefficient = 0;
          exponent = 1;
          next = null;
      }
  
      public IntegerNode(int c, int e) {
          coefficient = c;
          exponent = e;
          next = null;
      }
  
      public IntegerNode(int c, int e, IntegerNode n) {
          coefficient = c;
          exponent = e;
          next = n;
      }
  
      public void setCoefficient(int newCoefficient) {
          coefficient = newCoefficient;
      }
  
      public void setExponent (int newExponent) {
          exponent = newExponent;
      }
  
      public int getExponent() {
          return exponent;
      }//end getItem
  
      public int getCoefficient() {
          return coefficient;
      }//end getItem
  
      public void SetNext (IntegerNode nextNode) {
          next = nextNode;
      }//end setNext
  
      public IntegerNode getNext () {
          return next;
      }//end getNext
  
  }//end class IntegerNode
  
  class Driver {
  
  public static void main(String[] args) {
  
      //First polynomial:
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter coefficient: ");
      int coeff = sc.nextInt();
      System.out.println("Enter exponent: ");
      int exp = sc.nextInt();
      Stack&lt;IntegerNode&gt; p1 = new Stack&lt;IntegerNode&gt;();
      IntegerNode n = new IntegerNode(coeff, exp);
      p1.push(n);
      while (exp != 0){
          System.out.println("Enter coefficient: ");
          coeff = sc.nextInt();
          System.out.println("Enter exponent: ");
          exp = sc.nextInt();
          IntegerNode m = new IntegerNode(coeff, exp);
          p1.push(m);           
      }
  
      IntegerNode tail = p1.pop();
      IntegerNode head = null;
      while(!p1.empty()){
          head = p1.pop();
          head.SetNext(tail);
          System.out.println(head.getCoefficient() + " to " + tail.getCoefficient());
          tail = head;
      }
  
      IntegerNode cur = tail;
      while(!(cur.getNext()).equals(null)){
          System.out.println(cur.getCoefficient()+" "+cur.getExponent());
          System.out.println("NEXTNODE: " + cur.getNext().getCoefficient());
          cur = cur.getNext();
      }
      //Read in two integers, check each time if exponent is zero
      //create linked list in reverse order of input
      //Use stack to create LIFO list
  
  
  
      //Repeat above, but for second polynomial
  
      //Prompt user to choose which operation
      //Prompt user to specify what order if subtracted
  
      //iterate through p1
      //for every element in p1:
      //iterate through p2 and see if that element matches the current element
      //in p1. If so, then add their coefficients
      //Store results as you go
      //Output the results and indicate what operation was done
  
  
      // TODO Auto-generated method stub
  
  }
  </code></pre>
  
  <p>Here is the error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at Driver.main(IntegerNode.java:85)
  </code></pre>
  
  <p>That would be at my last while loop. Any ideas?</p>