我在寫兩個類來處理簡單的拍賣。我有一個課程已準備就緒,可以處理單次拍賣的操作,現在我正在寫一個像拍賣行一樣的課程,以跟蹤所有可用的拍賣。當測試類的以下部分:用下面的代碼的主方法內Java空指針異常
import java.util.ArrayList;
public class AuctionHouse {
private ArrayList<DutchAuction> huutokaupat;
public AuctionHouse() {
}
public void addAuction(DutchAuction newAuction) {
huutokaupat.add(newAuction);
}
}
(「kauppa」是測試和工作對象的變量):
AuctionHouse talo = new AuctionHouse();
talo.addAuction(kauppa);
我得到:
線程「main」中的異常java.lang.NullPointerException at ope.auction.dutch.AuctionHouse.addAuction(AuctionHouse.java:13) at ope.auction.dutch.DutchAuctionTest.main(DutchAuctionT est.java:54)
我該如何解決這個問題?