JavaFX Custom CellFactory Wrapper Throwing Null Pointer

前端 未结 1 902
有刺的猬
有刺的猬 2021-01-28 02:36

I have created a cell factory wrapper to enable custom configuration of a JavaFX table cell. See code below.

package idmas.controller.modules.tableview;

import          


        
相关标签:
1条回答
  • 2021-01-28 03:08

    There is no guarantee that the TableCell is already associated with a TableRow or that the TableRow is already filled when the updateItem method is called the first time.

    In your case probably getTableRow() returns null (which would mean however that cml = (Cml) cell.getTableRow().getItem(); is the line the exception is thrown, not String SQLString = "UPDATE IDMAS.CML SET CMLSTATUS = '<NEW_STATUS>' WHERE EQUIPMENT_ID = '" + cml.getEquipmentId() + "' AND CML_NO = " + cml.getCmlNo();); At least that happened when I tried to reproduce the error.

    However if

    String SQLString = "UPDATE IDMAS.CML SET CMLSTATUS = '<NEW_STATUS>' WHERE EQUIPMENT_ID = '" + cml.getEquipmentId() + "' AND CML_NO = " + cml.getCmlNo();
    

    is indeed the line causing the error, then the only way for that to happen that results in a stacktrace like this is if cml is null.

    A way to fix this would be getting the item from the table based on the index:

    cml = (Cml) cell.getTableView().getItems().get(getIndex());
    
    0 讨论(0)
提交回复
热议问题