Domanda

Ecco il codice che ho:

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

Ricevo errori:

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

Qualcuno mi può aiutare con questo?

È stato utile?

Soluzione

DefaultListModel ha solo un costruttore che non richiede argomenti; Non puoi passare i valori che desideri come arg di costruttore. Dovrai creare defaultListModel e poi popolarlo in seguito, per esempio:

HashMap<String, String> inst1 = new HashMap(instructorIO.getInstructors());
instListModel = new DefaultListModel<String>();
for (String value : inst1.values())
{
    instListModel.addElement(value);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top