在此代码中,foo()
是一个需要时间作为参数的函数。我想为多个功能实例设置计时器,每个实例具有相同的功能但参数不同。每个函数的参数是时间数组entryTimes
的每个元素,并且该函数应运行的时间也相同。 enterLength
是entryTimes
的长度。这是代码:
public void scheduler()
{
java.util.Timer[] _timer = new Timer[enterLength+1];
int i=0;
TimerTask[] tt = new TimerTask[enterLength+1];
for (i = 0; i < enterLength; i++) {
nowAt = i;
System.out.println(entryTimes[nowAt] + " : " + i +" 100");
tt[i] = new TimerTask() {
@Override
public void run() {
setMissedEntries(entryTimes[i]);
}
};
_timer[i].schedule(tt[i], entryTimes[i]);
System.out.println("Uff");
}
}
我一直收到java.lang.NullPointerException
异常。请帮忙。