This discussion is archived
1 Reply Latest reply: Dec 17, 2012 4:14 PM by eno g. - oracle RSS

NPE thrown while loading data into a table

eno g. - oracle Newbie
Currently Being Moderated
Since I will be loading large and/or multiple files I thought I would be able to start populating the table while reading the file(s), instead of waiting until they're all read and then loading the data into the table. For this, I decided to use Runnable start() instead of run() but now I get the following NPE:

Exception in thread "Thread-3" java.lang.NullPointerException
     at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:291)
     at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:48)
     at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.callObservers(ReadOnlyUnbackedObservableList.java:74)
     at javafx.scene.control.TableView$TableViewArrayListSelectionModel$3.onChanged(TableView.java:1725)
     at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:134)
     at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:48)
     at com.sun.javafx.collections.ObservableListWrapper.callObservers(ObservableListWrapper.java:97)
     at com.sun.javafx.collections.ObservableListWrapper.clear(ObservableListWrapper.java:184)
     at javafx.scene.control.TableView$TableViewArrayListSelectionModel.quietClearSelection(TableView.java:2154)
     at javafx.scene.control.TableView$TableViewArrayListSelectionModel.updateSelection(TableView.java:1902)
     at javafx.scene.control.TableView$TableViewArrayListSelectionModel.access$2600(TableView.java:1681)
     at javafx.scene.control.TableView$TableViewArrayListSelectionModel$8.onChanged(TableView.java:1802)
     at com.sun.javafx.scene.control.WeakListChangeListener.onChanged(WeakListChangeListener.java:71)
     at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:291)
     at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:48)
     at com.sun.javafx.collections.ObservableListWrapper.callObservers(ObservableListWrapper.java:97)
     at com.sun.javafx.collections.ObservableListWrapper.add(ObservableListWrapper.java:154)
     at com.sun.javafx.collections.ObservableListWrapper.add(ObservableListWrapper.java:144)
     at com.file.reader.FileReader.readFile(FileReader.java:89)
     at com.file.reader.FileReader.run(FileReader.java:33)
     at java.lang.Thread.run(Thread.java:722)

I am using the following code to loop through the choosen file(s) and kick off the respective threads. I figured that by passing the "data" ObservableList the threads will keep populating it and the table would grow dynamically. Which it does, until the above NPE is thrown at random points in the file.
ObservableList<RowLine> data = FXCollections.observableArrayList();
TableView<RowLine> tableView = new TableView<RowLine>(data);

private void openFiles(Stage _currentStage) {
File[] aOpenFiles = fileChooser.showOpenMultipleDialog(_currentStage).toArray(new File[0]);

        for (int file = 0; file < aOpenFiles.length; file++ )
     {
          if (!m_messageSource.containsKey(aOpenFiles[file].getAbsolutePath()))
          {
               Thread fileReader = new Thread(new FileReader(aOpenFiles[file].toPath(), m_config, data));
               fileReader.start();
          } else {
               System.out.println("You've already opened " + aOpenFiles[file].getAbsolutePath());
          }
     }
}
Am I completely wrong with populating the data this way?

TIA

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points