当我尝试添加和订购(之前已使用 Order 类创建)时,waitingList
我收到此错误:
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);
}
}