Error I receive:
Null pointer access: The variable listUsers can only be null at this location
Variable type String []:
String [] listadoUsuarios = null;
Code:
public void mostrarUsuariosExistentes() {
sSQL = "SELECT id_usuario FROM usuarios";
String [] listadoUsuarios = null;
int numFila = 0;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
pstm = conn.prepareStatement(sSQL);
rs = pstm.executeQuery(sSQL);
while (rs.next()) {
listadoUsuarios[numFila] = rs.getString("usuario");
numFila++;
}
} catch (SQLException errorSQL) { errorSQL.printStackTrace(); }
finally { // Cerramos las conexiones, en orden inverso a su apertura
try { if (rs != null) rs.close(); } catch (Exception errorPSTM) { errorPSTM.printStackTrace(); }
try { if (pstm != null) pstm.close(); } catch (Exception errorPSTM) { errorPSTM.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (Exception errorCONN) { errorCONN.printStackTrace(); }
}
}
What I'm trying to do is save all the login "users" of my table to show them in a JComboBox. With this you can select one and then show all your data in Textfield as your name, surname, password, etc. ..
I receive the error within while (rs.next())
.
Equal listadoUsuarios
as null
but, the error is still there.
Any ideas, or is it better to use ArrayList?