0
I’m doing a little program with a database and I can’t seem to get my list to appear in one jtable
. I created the method and at the time I call my method it error, someone can help me code this down?
Error:
Exception in thread "AWT-Eventqueue-0" java.lang.Nullpointerexception at presentcao.TelaCliente.formInternalFrameOpened(Telacliente . java:593)
List method
public List<cliente>preencherTabela(){
String sql = "select * from cliente";
cliente c=new cliente();
List<cliente> lista = new ArrayList<>();
try(PreparedStatement stmt = conexao.prepareStatement(sql)){
ResultSet rs = stmt.executeQuery();
while(rs.next()){
c.setIdcodigo(rs.getInt("idcodigo"));
c.setNome(rs.getString("nome"));
c.setEndereco(rs.getString("endereco"));
c.setEmail(rs.getString("email"));
c.setCidade(rs.getString("cidade"));
c.setBairro(rs.getString("bairro"));
c.setTelefone(rs.getString("telefone"));
c.setCelualr(rs.getString("celular"));
c.setCep(rs.getString("cep"));
c.setRg(rs.getString("rg"));
c.setCpf(rs.getString("cpf"));
c.setDatanascimento(rs.getString("datanascimento"));
c.setUf(rs.getString("uf"));
c.setSexo(rs.getString("sexo"));
}
}catch (SQLException ex) {
JOptionPane.showMessageDialog(null,"Usuario nao encontrado" + ex);
}
return lista;
}
}
code to call the method
private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
cliente c = new cliente();
List<cliente> lista = new ArrayList<>();
Conexao con=null;
lista=con.preencherTabela();
for(int i=0;i<lista.size();i++){
c=lista.get(i);
jPcad.setValueAt(c.getIdcodigo(), i, 0);
jPcad.setValueAt(c.getNome(), i, 1);
}
}
You need a space between the return type and the method name": public List<client> fillTable() {
– ℛɑƒæĿᴿᴹᴿ
@n3uRoQuiLa this must have been error when copying here on the site, otherwise his code would not even compile and pop the nullpointerexception on the informed line.
– user28595
Sure, it was just a sign.
– ℛɑƒæĿᴿᴹᴿ
how do I fix it, I couldn’t, can help me!!!
– ThiJoe
@Thijoe just make the suggested changes in the reply.
– user28595
I did, but did not give, you can show please!!!
– ThiJoe
@Thijoe what problem occurs?
– user28595
it does not occur any error now, more when I start my program , it was to load the lists in the table , more does not appear
– ThiJoe
@Thijoe ai is already another problem other than your original question. It would be interesting to end this by accepting the answer by clicking on
v
and create a new question with this new question, placing the link here as reference.– user28595
thanks brother , excuse the delay to respond , I am very busy and I have little time to respond , thanks brother
– ThiJoe