编译时提示Polynomial类里add方法的pc.next = pa;pc = pa;pa = pa.next;语句有null pointer exception
public class Term {
public double coef;
public int exp;
public Term next;

Term(double coef,int exp){
this(coef,exp,null);
}

Term(double coef,int exp,Term next){
this.coef = coef;
this.exp = exp;
this.next = next;
}
}public class Polynomial {
Term header = new Term(0,0);

public Polynomial(){
zeroPolynomial();
}

public boolean isEmpty(){
return header == null;
}
public void insertTerm(double coef,int exp){
if (isEmpty()){
header = new Term(coef,exp);
}
else{
Term temp = header;
while (temp.next != null){
temp = temp.next;
}
Term term = new Term(coef,exp);
temp.next = term;
}
}

public void zeroPolynomial(){
header = null;
}

public Polynomial add(Polynomial b){
Term pa,pb,pc;
double temp;
Polynomial c = new Polynomial();

pa = header.next;
pb = b.header.next;
pc = c.header;
while (pa != null && pb != null){
if (pa.exp == pb.exp){
temp = pa.coef + pb.coef;
pb = pb.next;
if (temp == 0.0){
pa = pa.next;
}
else{
pc.next = pa;pc = pa;pa = pa.next;
}
}
else if( pa.exp < pb.exp){
pc.next  = pb;pc = pb;pb = pb.next;
}
else{
pc.next = pa;pc = pa;pa = pa.next;
}
}
if (pb == null) pc.next = pa;
else pc.next = pb;
return c;
}
public void print(){
for (Term temp = header;temp != null;temp = temp.next){
if (temp.next == null){
System.out.print(temp.coef + "X^" + temp.exp);
}
else{
System.out.print(temp.coef + "X^" + temp.exp + " + ");
}
}
System.out.println();
}
}public class testPolynomial {
public static void main(String args[]){
Polynomial a = new Polynomial();
Polynomial b = new Polynomial();
a.insertTerm(2,100);
a.insertTerm(3,14);
a.insertTerm(2,8);
a.insertTerm(1,0);
b.insertTerm(-2,100);
b.insertTerm(8,14);
b.insertTerm(-3,10);
b.insertTerm(10,6);
b.insertTerm(-1,1);
Polynomial c = a.add(b);
c.print();
}
}