I'm doing a project to send packages in Java and I'm having a problem loading a combobox with data brought from a database. In the stack trace I am returning as error what can be seen in the image, and according to what I observed the line 239 that is referenced is when I try to add an element in the combobox, which returns me as a result Null . Of course, whoever is kind enough to help me will be grateful. Greetings
Here is my code to fill the combobox, I have it in a separate class called UsuarioDAO
public void usuarios_combo(JComboBox cbox_usuarios){
try {
String sql = "SELECT usu_ci FROM usuarios";
Connection conn = this.getConexion();
PreparedStatement pst1 = conn.prepareStatement(sql);
pst1.setQueryTimeout(5);
ResultSet rs = pst1.executeQuery();
while ((rs != null) && (rs.next())) {
String ci = rs.getString(1);
cbox_usuarios.addItem(ci);
}
pst1.close();
rs.close();
conn.close();
}
catch (Exception e) {
System.err.println("Names : " + e.getClass().getName() + ": " + e.getMessage());
e.printStackTrace();
}
}
Then in the presentation (the form where I show the parcels) I have the following:
public class ListarEncomiendasAdmin extends JFrame {
private JPanel contentPane;
private JTextField txtEstado;
private JTextField txtOrigen;
private JTextField txtDestino;
private static JTable tblEncomiendas;
private static EncomiendasDAO eDAO = new EncomiendasDAO();
private static Object[][] dtEncomienda;
private static JComboBox cmbRemitente;
private static JComboBox cmbDestinatario;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
UsuarioDAO uDAO = new UsuarioDAO();
try {
ListarEncomiendasAdmin frame = new ListarEncomiendasAdmin();
frame.setVisible(true);
Actualizar_Tabla();
uDAO.usuarios_combo(cmbRemitente);
uDAO.usuarios_combo(cmbDestinatario);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}