我被困在這條路上,它真的開始讓我感到沮喪。我想我有一切正常工作,但這一個方法。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