gpt4 book ai didi

java - HashMap 到 DefaultListModel

转载 作者:行者123 更新时间:2023-12-01 15:31:31 25 4
gpt4 key购买 nike

这是我的代码:

HashMap<String, String> inst1 = new HashMap(instructorIO.getInstructors());
instListModel = new DefaultListModel<String>(inst1.values());

我收到错误:

DepartmentProject.java:69: error: constructor DefaultListModel in class DefaultListModel<E> cannot be applied to given types;
required: no arguments
found: Collection<String>
reason: actual and formal argument lists differ in length
where E is a type-variable:
E extends Object declared in class DefaultListModel

谁能帮我解决这个问题吗?

最佳答案

DefaultListModel 只有一个不带参数的构造函数;您无法将所需的值作为构造函数参数传递。您必须创建 DefaultListModel,然后填充它,例如:

HashMap<String, String> inst1 = new HashMap(instructorIO.getInstructors());
instListModel = new DefaultListModel<String>();
for (String value : inst1.values())
{
instListModel.addElement(value);
}

关于java - HashMap 到 DefaultListModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9474479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com