当我调用我的类的构造函数时,我得到了注释中显示的错误(当我删除数组部分时一切正常)。这是因为数组声明错误seq
吗?
public class FibIt implements SeqIt{
public int counter;
public int ptr;
public int [] seq;
public FibIt(Fib x)
{ counter=0;
ptr=0;
seq[0]=x.first1; //gives me an error here saying Exception in
//thread "main" java.lang.NullPointerException
//at FibIt.<init>(FibIt.java:9)
//at Main.main(Main.java:6)
seq[1]=x.first2;
for (int i=2; seq[i-1]<=x.last; i++)
{seq[i]=seq[i-1]+seq[i-2];}
}
@Override
public int func2() {
// TODO Auto-generated method stub
ptr++;
return seq[ptr-1];
}
}