1

How should I correct the following issue?

The following code works on a JTable with 4-columns without tripping a Null Pointer Exception:

 public void setSubject() {
    try {


        int row = table_SPAssignList.getSelectedRow();
        String prop_addr1_ = (table_SPAssignList.getModel().getValueAt(row, 0)).toString();
        String prop_id_ = (table_SPAssignList.getModel().getValueAt(row, 3)).toString();


        /*
         * UPDATE TriTier to set Subject Property
         */
        dbConn = sqliteConnection.dbConnector();
        String query = "UPDATE TABLENAME SET sp_id = " + prop_id_ + " where id = " + tID;
        PreparedStatement pst = dbConn.prepareStatement(query);
        pst.execute();
        pst.close();

        /*
         * Display Subject Property Information on Panel
         * 
         */
        String addr = prop_addr1_ ;
        label__SPAssignDBID.setText(prop_id_);
        label_SPAssignAddress.setText(addr);

    } catch (final Exception getProperty) {
        getProperty.printStackTrace();
    }
}

However, if I insert the following code, between the getValueAt(row, 0) and getValueAt(row, 3) lines of code a null pointer error seems to occur if the field does not contain data:

String prop_addr2_ = (table_SPAssignList.getModel().getValueAt(row, 1)).toString();
String prop_zip_ = (table_SPAssignList.getModel().getValueAt(row, 2)).toString();

It is very likely that these fields, within the database, do not have any data. Columns 0 and 3, of the table_SPAssignList object will always have values in them.

I am connecting to a SQLite database.

The following posts may be related to my issue

(update data from jTable to database -null pointer exception error) and (getValueAt() method returns null)

Community
  • 1
  • 1
EricG
  • 65
  • 9

0 Answers0