您好我在尝试从ArrayList输出项目,如果用户输入匹配ArrayList中的itemNumber ..我正在使用一个,这些是覆盖方法。
实现的接口方法:
package Purchase;
import java.util.*;
public class Items implements recordItem {
String description;
ArrayList<Items> itemList = new ArrayList<Items>();
public static Items newItems = new Items();
答案 0 :(得分:1)
你的问题在这里:
this.itemNumber = itemNumber;
this.description = description;
this.unitPrice = unitPrice;
this.sort = sort;
Items theItems = new Items();
itemList.add(theItems);
你正在添加一个空的&#34; Items&#34;列表。
这将有效:
Items theItems = new Items();
theItems.itemNumber = itemNumber;
theItems.description = description;
theItems.unitPrice = unitPrice;
theItems.sort = sort;
itemList.add(theItems);
请永远不要使用像
这样的静态实例public static Items newItems = new Items();
在您的实体类中。