當我嘗試添加和順序(先前已與Order類創建)爲waitingList
我得到這個錯誤:Java代碼想出錯誤
java.lang.NullPointerException
at DeliveryLog.addOrder(DeliveryLog.java:41)
我使用BlueJ的寫我的Java代碼。
下面是代碼:
import java.util.*;
/**
* Write a description of class DeliveryLog here.
*
* @author Stefan Lazic
* @version 1
*/
public class DeliveryLog
{
private Date logDate;
private int numberOfOrders;
private ArrayList<Order> waitingList;
private ArrayList<Order> deliveredList;
/** constructor
* @param dd day
* @param mm month
* @param yy year
*/
public DeliveryLog(int dd, int mm, int yy)
{
//Initialses the log date and sets the default order value to 0
logDate = new Date (dd,mm,yy);
numberOfOrders = 0;
ArrayList<Order> waitingList = new ArrayList<Order>();
ArrayList<Order> deliveredList = new ArrayList<Order>();
}
public int getCallIns(int dd, int mm , int yy)
{
return numberOfOrders;
}
public int getOrdersWaiting()
{
return waitingList.size();
}
public void addOrder (Order order)
{
waitingList.add(order);
}
}