編譯程序時我沒有問題,但是當我嘗試運行該程序時,我得到一個NullPointerException。我不知道爲什麼我有這個和如何擺脫這一點。Queue isEmpty疑難解答
錯誤是在這條線:
public boolean isEmpty(){
代碼:
public class TheChair {
private Customer[] chairQueue = null;
public void TheChair(){
chairQueue = new Customer[1];
}
public void enchairQueue(Customer newItem){
if(chairQueue[0] == null){
chairQueue[0] = newItem;
}
else{
System.out.println("The chair is full.");
}
}
public void dechairQueue(){
System.out.println(chairQueue[0].getName() + " has left");
chairQueue[0] = null;
}
public boolean isEmpty(){
if(chairQueue[0] == null){
System.out.println("The Barber's chair is empty");
System.out.println();
return true;
} else{
System.out.println("The Barber's chair is filled by: ");
System.out.println(chairQueue[0].getName());
return false;
}
}
我真的不知道應該怎麼解決這一點,這是程序的代碼只是一小部分。
這只是類定義。你還可以包含你正在運行的單元測試或應用程序代碼嗎? – Horus 2013-04-28 22:22:59
這裏張貼的代碼太多,所以我會設置一個鏈接來查看。 http://www.mediafire.com/?x2oaxmz1fb866 – Jaylon253 2013-04-28 22:28:12