Note that there are some explanatory texts on larger screens.

plurals
  1. POSimpleDoubleProperty.set(double) throwing NPE
    primarykey
    data
    text
    <p>I have a small financial application that is showing a market data watch list (current bid price/current ask price) in a TableView.</p> <p>The bid/ask prices are being updated in real time for each of the symbols that I'm watching.</p> <p>Everything works exceptionally well, but occasionally I get a NullPointerException when trying to set either the bid or sometimes the ask price.</p> <p>Here's a snippet from my GUI Controller that sets up the TableView and Columns</p> <pre><code>TableColumn&lt;PositionRowData, Number&gt; bidColumn = new TableColumn&lt;PositionRowData, Number&gt;(BID_COLUMN_NAME); TableColumn&lt;PositionRowData, Number&gt; askColumn = new TableColumn&lt;PositionRowData, Number&gt;(ASK_COLUMN_NAME); TableColumn&lt;PositionRowData, Number&gt; lastColumn = new TableColumn&lt;PositionRowData,Number&gt;(LAST_COLUMN_NAME); . . . //and later on the column is initialized like this bidColumn.setCellFactory(new USDTableCellRenderer()); bidColumn.setCellValueFactory(new Callback&lt;TableColumn.CellDataFeatures&lt;PositionRowData,Number&gt;, ObservableValue&lt;Number&gt;&gt;() { @Override public ObservableValue&lt;Number&gt; call( CellDataFeatures&lt;PositionRowData, Number&gt; arg0) { return arg0.getValue().getBid(); } }); //finally the columns are added to the table TableView.getColumns().addAll(....bidColumn..etc); </code></pre> <p>Here's a snippet from my PositionRowData constructor with initialization:</p> <pre><code>bid = new SimpleDoubleProperty(); ask = new SimpleDoubleProperty(); </code></pre> <p>Here's what my setter code looks like: </p> <pre><code>public void setBid(double bid) { try { this.bid.set(bid); } catch (NullPointerException e) { _log.error("Would have been NPE in setBid. trying to set new value: "+bid); } } </code></pre> <ul> <li>Btw - It's not my usual habit to catch my NPEs! I just stuck that in there because I wanted a more graceful error for the person who was testing this for me!</li> </ul> <p>Here's the full stack trace:</p> <pre><code>2013-06-20 11:56:12,500 ERROR [DataChannel Reader Thread] - NPE java.lang.NullPointerException at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(Unknown Source) at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(Unknown Source) at javafx.beans.property.DoublePropertyBase.fireValueChangedEvent(Unknown Source) at javafx.beans.property.DoublePropertyBase.markInvalid(Unknown Source) at javafx.beans.property.DoublePropertyBase.set(Unknown Source) at com.eak070.ui.tablemodel.PositionRowData.setAsk(PositionRowData.java:86) at com.eak070.ui.ETGUIController.onQuote(ETGUIController.java:808) at com.eak070.ui.ETGUIController$24.handleDataChannelMessage(ETGUIController.java:737) at com.eak070.communication.stream.DataChannel.processDataChannelMessage(DataChannel.java:211) at com.eak070.communication.stream.DataChannel.readFromSocketChannel(DataChannel.java:156) at com.eak070.communication.stream.DataChannel.access$1(DataChannel.java:122) at com.eak070.communication.stream.DataChannel$1.run(DataChannel.java:99) </code></pre> <p>I'm not quite sure what's going on as I'm still somewhat new to JavaFX and don't really know the ins and outs of bindings.</p> <p>This appears to be happening sporadically. In other words I can't yet reproduce it on purpose. It just happens seemingly randomly.</p> <p>This feels like it might be a threading issue, but I'm just not sure why there's a NPE inside of the set() method since rows in this table aren't being destroyed. Once rows are created they hang around forever. Any advice/thoughts appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload