Java Code Error Help..please
<p>I am getting the following error and do not know how to fix it....any help would be great...Thanks</p>

<pre><code>Exception in thread "main" java.lang.NullPointerException
        at Polynomial.add(Polynomial.java:115)
        at PolyTest.main(PolyTest.java:18)
</code></pre>

<p>Ok Well here is the cod for Polynomial add() method </p>

<pre><code>  public static Polynomial add(Polynomial p, Polynomial q)
        {
            Polynomial r = new Polynomial();
            double coefficient;
            int exponent;
            termNode first = p.head;
            termNode second = q.head;
            termNode sum = r.head;
            termNode term;
            while (first != null &amp;&amp; second != null)
                {
                    if (first.getExp() == second.getExp())
                        {
                            if (first.getCoeff() != 0 &amp;&amp; second.getCoeff() != 0);
                            {
                                double addCoeff = first.getCoeff() + second.getCoeff();
                                term = new termNode(addCoeff,first.getExp());
                                sum.setNext(term);
                                first.getNext();       //&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Line 115
                                second.getNext();
                            }
                        }
                    else
                        if (first.getExp() &lt; second.getExp())
                        {
                            sum.setNext(second);
                            term = new termNode(second.getCoeff(),second.getExp());
                            sum.setNext(term);
                            second.getNext();
                        }
                    else
                        {
                            sum.setNext(first);
                            term = new termNode(first.getNext());
                            sum.setNext(term);
                            first.getNext();
                        }
                }
            while (first != null)
                {
                    sum.setNext(first);
                }
            while (second != null)
                {
                    sum.setNext(second);
                }
            return r;
        }
</code></pre>

<p>Here is the Code for the Call...class PolyTest</p>

<pre><code>import java.util.Scanner;

class PolyTest{

    public static void main(String [] args)
    {
        Scanner s = new Scanner(System.in);
        Polynomial r;
        Polynomial p = new Polynomial();
        System.out.println("Enter First Polynomial.");
        p.readPolynomial(s);
        System.out.println(p);
        Polynomial q = new Polynomial();
        System.out.println();
        System.out.println("Enter Second Polynomial.");
        q.readPolynomial(s);
        System.out.println(q);
        r = Polynomial.add(p,q);
        System.out.println();
        System.out.print("The sum of ");
        System.out.println(p);
        System.out.print(" and ");
        System.out.println(q);
        System.out.print(" is ");
        System.out.println(r);
    }
}
</code></pre>

<p>Here is my ToString() method aswell. Might be helpful. </p>

<pre><code> public String toString()
    {
        String s = new String("Poly = ");
        termNode temp = head;
        while (temp != null)
            {
                s = s + temp;
                temp = temp.getNext();
            }
        return s;
    }
</code></pre>
