I am writing a program that requires me to read in a predetermined file and add the numbers given into polynomial format. I keep getting a NullPointerException when the code reaches the end of a file. Here is the snippit of code that gives me the error:
The error is occurring on line 11 and/or 12.
public IList<Integer, Term> add(IList<Integer, Term> p1, IList<Integer, Term> p2)
{
IList<Integer, Term> addList = new LList<Integer, Term>();
//If the keys of both list equal each other, add them to the term
//being placed inside of addList
//
if(p1.getSize() >= p2.getSize() || p2.getSize() <= p1.getSize()){
//Here is where the error is happening --v
for(int i = 0; i < 10; i++){
if(p1.find(i).equals(p2.find(i))){
Term t1 = p1.find(i);
Term t2 = p2.find(i);
int c1 = t1.getCoef();
int c2 = t2.getCoef();
int c3 = c1 + c2;
Term t3 = new Term(c3, i);
//Add the added term, at the location of the previously added terms location
addList.add(i, t3);
}
}
}
return addList;
}
Any help with this program will be more than helpful. Thanks