我被困在这条路上,它真的开始让我感到沮丧。我想我有一切正常工作,但这一个方法。nullpointerexception错误删除节点
当我从我的LL中删除一个节点我得到一个空指针异常下一次尝试,我不知道什么。
public void timeSlice(int cpuTime){
for(Node curr=head; curr.getNext()!=head; curr=curr.getNext()){
curr.time=curr.time-cpuTime;
System.out.print("<" + curr.pid + ", " + curr.time +">" + " ");
//if the time remaining <= 0 then remove the node
if(curr.time<=0){
System.out.println("\nProcess " + curr.pid + " has finished, and is now being terminated");
remove(curr);
}
}
}//end timeSlice
它在删除和重新启动该方法后发生。我认为这是因为我刚刚删除了curr,但我不是100%确定的。
public void remove(Node node){
if(size == 0){
return;
}
else if(size == 1){
removeFirst();
}
else{
Node curr;
for(curr=head; curr.getNext()!=node; curr=curr.getNext()){
;
}
curr.setNext(curr.getNext().getNext());
node.setNext(null);
}
size --;
}//end remove
现在目前的测试是,它会删除倒数第二个节点
你的remove()方法的来源是什么? – Catherine 2013-04-22 02:24:24
@Catherine the remove is up – kevorski 2013-04-22 02:27:46