title: NullPointerException in JavaFX initialize method
body: <p>I have controller and there I trying get INBOX folder from e-mail server. With downloading everything is ok. I can put this data(email subject,from,date) into TableView but... only when I am waiting for thread responsible for set this data in TableView. 
  Code:</p>
  
  <pre><code>// The table and columns
  @FXML
  TableView&lt;MainModel.Item&gt; itemTbl;
  @FXML
  TableColumn itemNameCol;
  @FXML
  TableColumn itemQtyCol;
  @FXML
  TableColumn itemTitleCol;
  // The table's data
  static ObservableList&lt;MainModel.Item&gt; data;
  
  public void dataSet(){
      // Set up the table data
      itemNameCol.setCellValueFactory(
          new PropertyValueFactory&lt;MainModel.Item,String&gt;("name")
      );
      itemQtyCol.setCellValueFactory(
          new PropertyValueFactory&lt;MainModel.Item,String&gt;("qty")
      );
      itemTitleCol.setCellValueFactory(
          new PropertyValueFactory&lt;MainModel.Item,String&gt;("title")
      );
  
      data = FXCollections.observableArrayList();
      itemTbl.setItems(data);
  }
  
  public void setEnemyEvent() {
      itemTbl.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler&lt;MouseEvent&gt;() {
          @Override
          public void handle(MouseEvent event) {
              if (event.getClickCount() == 2) {
                  if(itemTbl.getSelectionModel().getSelectedItem()!=null){
                      System.out.println(itemTbl.getSelectionModel().getSelectedItem().name);
                  }
              }
          }
      });
  }
  
  @Override
  public void initialize(URL url, ResourceBundle rb) { 
      setEnemyEvent();
      dataSet();
      Thread t = new Thread(new MessageLoop());
      //HERE:
      t.start();
      //of course normally here is try and catch
      t.join();
  }
  
  //staric nested class "for loop"
  private static class MessageLoop implements Runnable {
      public void run() {
          try {
              EmailConnetion con = new EmailConnetion();
              MainModel MainModel = new MainModel();
              for(int i=0;i&lt;con.message.length;i++){
                  try{
                      MainModel.Item item = MainModel.new Item();
                      item.name.setValue(i+""+con.message[i].getFrom()[0].toString());
                      item.qty.setValue(con.message[i].getSentDate().toString());
                      item.title.setValue(con.message[i].getSubject().toString());
                      //Here is a problem.
                      data.add(item);//This indicate my IDE  
                      //*****************
                  } catch(AddressException e) {
                      System.out.println("Error : " + "AddressException:"+i);
                  }
              }
          } catch (NoSuchProviderException ex) {
              Logger.getLogger(SimpleController.class.getName()).log(Level.SEVERE, null, ex);
          } catch (MessagingException ex) {
              Logger.getLogger(SimpleController.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  }
  </code></pre>
  
  <p>When i remove t.join() it will throw this NullPointerException.</p>
  
  <pre><code>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 javasplitpane.SimpleController$MessageLoop.run(SimpleController.java:95)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>This appear in different position, in fourteen email, thirty email. You have some ideas ? </p>
  
  <p>p.s I can't wait for this downloading because it takes 20 sec. with 50 emails - I have to do it during initialize.</p>