我正在编写一个程序,该程序需要我读取预定文件并将给定的数字添加为多项式格式。当代码到达文件末尾时,我不断收到 NullPointerException。这是给我错误的代码片段:
错误发生在第 11 行和/或第 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;
}
对这个程序的任何帮助都将非常有帮助。谢谢