0

I am wondering why do I get NPE in the following code:

@Override
public void updateItem(String item, boolean empty) {
    if(empty){
        super.updateItem(item, empty);
        return;
    }
    MyTableRow currentRow = (MyTableRow) getTableRow().getItem();
    currentRow.stringProperty(); // here I get NPE
}

The code snippet is from a custom TableCell, where the updateItem is overridden. At the commented line I get NPE, while the item is not null, and also empty is false. For me that means there is a row, so the getTableRow().getItem() should not be null. That is true and is a solution(or an unnecessary workaround?) to make a nullcheck after I get the item's reference, but I think that is unnecessary. Did I missed or this is an expected outcome?

Sunflame
  • 2,993
  • 4
  • 24
  • 48
  • Yes, that's what I meant, though you have another bug I didn't spot immediately. – James_D Aug 28 '17 at 15:19
  • For obvious reasons I cannot post the whole code, I thought that you(or somebody else) already had this problem, so you can suggest the respective part where I missed something or I did wrong something, I will take a deeper look at why this occurs, until I find it I will just use the line from the other question's answer that is mentioned by fabian because of duplication. – Sunflame Aug 28 '17 at 15:36
  • No-one asked you to post your whole project. I see absolutely no reason why you couldn't post a [MCVE] for this. However, the question is already answered in the dupe. – James_D Aug 28 '17 at 15:37

0 Answers0