Pass HashMap to JList

0

I want to pass the data of players to a list from which to perform actions such as unsubscribe, etc (in a jframe). It's a poker game, players have ID, name, etc.

My idea is to execute the following method in the main of the jFrame:

public void getJugadores() {
    //Cargo el hashmap serializado de jugadores:
    HashMap<String, Jugador> jugadores = null;
    jugadores = ca.cargaHashMap(jugadores);

    DefaultListModel listModel = new DefaultListModel();
    ArrayList<Jugador> jugadores_arr = new ArrayList<Jugador>(jugadores.values());

    for (int i = 0; i < jugadores_arr.size(); i++) {
        listModel.addElement(jugadores_arr.get(i).toString());
    }
    lista_jugadores.setModel(listModel);

}

As you can see I have passed a serialized hashmap to an array (players_arr), and I have tried to use a defaultlistmodel to load the player data and then add it to the list. The problem is that when executing I get this:

And I do not know how to solve it. I understand that the error is a pointer to something empty, but I do not know how to fix it or where the error is.

Am I doing it the right way? Is there a simpler or more correct way to pass a hashmap to a list? What is failing?

    
asked by Marcos 13.05.2017 в 17:04
source

0 answers