-3

Hi guys i have a NullPointerException when i run this code ,and its pointing on the model = (DefaultTableModel) DbUtils.resultSetToTableModel(rs) , and i have imported the net.proteanit.sql.DbUtils , any ideas ?

public void setTableValues(){
         try {
             cn.start();
             String sql = "select id,first_name as Firstname,last_name as Lastname,email,phone,description as AllergyInfo from clients where isDeleted=0";
             rs = cn.executeSelect(sql);
             model = (DefaultTableModel) DbUtils.resultSetToTableModel(rs);
             jTable1.setModel(model);
             rowSorter = new TableRowSorter<>(jTable1.getModel());
             jTable1.setRowSorter(rowSorter);
             cn.stop();
         } catch (SQLException ex) {
             Logger.getLogger(Clients.class.getName()).log(Level.SEVERE, null, ex);
         }
    }
A.Antho
  • 7
  • 1
  • 1
    (1-) A variable is null. Figure out which variable is null, by adding System.out.println(...) statements for each variable you access in that statement. Don't expect to ask a question every time you get a NullPointerException. – camickr May 05 '18 at 19:39
  • 2
    Please learn how to debug code. – juergen d May 05 '18 at 19:40

1 Answers1

2

Use any IDE like eclipse to debug your code to add breakpoints and get to know which variable is null and that will be pointing to null pointer exception.

And you can add null check in your code to prevent null pointer exception like

If (object != null)

SSV
  • 35
  • 1
  • 1
  • 10