我有 PurchaseOrder objectPO = new PurchaseOrder(objectPO.getDateOfOrder(), "CGL-1234" ,objectPO.getProductType(), 250, 5); objectPO.toString();但我收到错误消息,可能未初始化objectPOPurchaseOrder class我浏览过类似的帖子,但找不到有关我的错误的解决方案。如何初始化objPO? 最佳答案 问题在于,即使创建objectPO.getDateOfOrder()对象,也无法调用objectPO.getProductType()和objectPO方法,即,您正在尝试使用objectPO本身(这是构造函数调用)。相反,首先通过使用如下类的构造函数为objectPO(如PurchaseOrder)和OrderDate(如orderDateObj)创建对象,然后将这些对象传递给创建Product对象。OrderDate orderDateObj = new OrderDate(...);//create object for OrderDateProduct productObj = new Product(...);//create object for ProductPurchaseOrder objectPO = new PurchaseOrder(orderDateObj, "CGL-1234" , productObj, 250, 5);
07-25 20:26