title: Why TableView makes NullPointerException?
body: <p>I have this controller class for showing the data of the method "getProduct" in a TableView, but I have a NullPointerException related to "tableViewItem.setItems(itemData)". I read some posts about this topic but didn't solve the problem.          </p>
  
  <pre><code>package configuradordepc.controller;
  
  //All imports
  
  public class ControladorView implements Initializable {
  
      @FXML private MenuItem mNew, mOpen, mSave, mPrint;
  
      @FXML
      private MenuItem mMother, mCPU, mRAM, mGPU, mHardDrive, mCase, mKey, mMouse,
                       mScreen, mSpeak, mMulti, mDVD, mFan, mPower;
  
      @FXML private Button bSearch, bAdd, bRemove, bClean;
  
      @FXML private TableView tableViewItem;
      @FXML private TableColumn&lt;Product, String&gt; nameItemColumn;
      @FXML private TableColumn&lt;Product, Double&gt; priceColumn;
      @FXML private TableColumn&lt;Product, Integer&gt; availableColumn;
  
      private ObservableList&lt;Product&gt; itemData;
  
      @FXML private TableView tableViewBudget;
      @FXML private TableColumn&lt;Product, String&gt; nameBudgetColumn;
      @FXML private TableColumn&lt;Product, Double&gt; outTaxColumn;
      @FXML private TableColumn&lt;Product, Double&gt; inTaxColumn;
      @FXML private TableColumn&lt;Product, Integer&gt; quantityColumn;
  
      private ObservableList&lt;Product&gt; budgetData;
  
      @FXML private TextField tFSearch, tFMin, tFMax;
  
      //Errors from TableView
      @Override
      public void initialize(URL location, ResourceBundle resources) {
          //Items Table
          nameItemColumn.setCellValueFactory(
              new PropertyValueFactory&lt;&gt;("description"));
          priceColumn.setCellValueFactory(
              new PropertyValueFactory&lt;&gt;("price"));
          availableColumn.setCellValueFactory(
              new PropertyValueFactory&lt;&gt;("stock"));
  
          itemData = FXCollections.observableArrayList();
          getProduct();
          tableViewItem.setItems(itemData);
  
          //Budget Table
          nameBudgetColumn.setCellValueFactory(
              new PropertyValueFactory&lt;&gt;("description"));
          inTaxColumn.setCellValueFactory(
              new PropertyValueFactory&lt;&gt;("price"));
  
          budgetData = FXCollections.observableArrayList();
          tableViewBudget.setItems(budgetData);
  
          //Bindings Item
          final BooleanBinding noItemSelectedI = Bindings.isNull(
              tableViewItem.getSelectionModel().selectedItemProperty());
          final BooleanBinding emptySearch = Bindings.isEmpty(tFSearch.textProperty());
  
          //Bindings Budget
          final BooleanBinding noItemSelectedB = Bindings.isNull(
              tableViewBudget.getSelectionModel().selectedItemProperty());
          final BooleanBinding emptyBudget = Bindings.isEmpty(tableViewBudget.getItems());
  
          //Disable botones
          bSearch.disableProperty().bind(emptySearch);
          bAdd.disableProperty().bind(noItemSelectedI);
          bRemove.disableProperty().bind(noItemSelectedB);
          bClean.disableProperty().bind(emptyBudget);
      }
  
      @FXML
      private void onSearch(ActionEvent event) {
  
      }
  
      @FXML
      private void onAdd(ActionEvent event) {
          budgetData.add((Product) tableViewItem.getSelectionModel().selectedItemProperty().getValue());
      }
  
      @FXML
      private void onDelete(ActionEvent event) {
  
      }
  
      @FXML
      private void onClean(ActionEvent event) {
  
      }
  
      //Item Table initialization
      public void getProduct() {
          //SPEAKER
          itemData.add(new Product("Logitech Z213 Multimedia Speakers 2.1", 22.95, 50, SPEAKER));
          //HDD
          itemData.add(new Product("Seagate Barracuda 7200.14 1TB SATA3", 46.95, 100, HDD));
          //HDD_SSD
          itemData.add(new Product("Samsung 850 Evo SSD Series 250GB SATA3", 82, 65, HDD_SSD));
          //POWER_SUPPLY
          itemData.add(new Product("Tacens Mars Gaming 700W", 42.75, 25, POWER_SUPPLY));
          //DVD_WRITER
          itemData.add(new Product("LG GH24NSD1 Grabadora DVD 24x Negra", 12.95, 55, DVD_WRITER));
          //RAM
          itemData.add(new Product("G.Skill Ripjaws X DDR3 1600 PC3-12800 8GB 2x4GB CL9", 37.95, 80, RAM));
          //SCREEN
          itemData.add(new Product("LG 22M47VQ-P 21.5 LED", 115, 10, SCREEN));
          //MULTIREADER
          itemData.add(new Product("Unotec Lector USB de tarjetas SD/MicroSD", 3.95, 110, MULTIREADER));
          //MOTHERBOARD
          itemData.add(new Product("Gigabyte GA-H81M-S2H", 49.95, 75, MOTHERBOARD));
          //CPU
          itemData.add(new Product("Intel Core i5-4460 3.2Ghz Box", 175, 490, CPU));
          //MOUSE
          itemData.add(new Product("Logitech Wireless Mouse M175 Negro", 12.95, 200, MOUSE));
          //GPU
          itemData.add(new Product("Gigabyte GeForce GTX 970 Gaming G1 WindForce OC 4GB GDDR5", 354, 480, GPU));
          //KEYBOARD
          itemData.add(new Product("Nox Krom Kombat Teclado + Ratón", 30.99, 54, KEYBOARD));
          //CASE
          itemData.add(new Product("NOX Sense 500W + Frontal", 41.95, 65, CASE));
          //FAN
          itemData.add(new Product("Cooler Master Hyper TX3 EVO CPU Cooler", 21.50, 220, FAN));
      }
  }
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre><code>ant -f C:\\Users\\Marco\\Desktop\\ConfiguradorDePC jfxsa-run
  init:
  Deleting: C:\Users\Marco\Desktop\ConfiguradorDePC\build\built-jar.properties
  deps-jar:
  Updating property file: C:\Users\Marco\Desktop\ConfiguradorDePC\build\built-jar.properties
  Compiling 2 source files to C:\Users\Marco\Desktop\ConfiguradorDePC\build\classes
  Note: C:\Users\Marco\Desktop\ConfiguradorDePC\src\configuradordepc\controller\ControladorView.java uses unchecked or unsafe operations.
  Note: Recompile with -Xlint:unchecked for details.
  compile:
  Deleting directory C:\Users\Marco\Desktop\ConfiguradorDePC\dist\lib
  Copying 1 file to C:\Users\Marco\Desktop\ConfiguradorDePC\dist\lib
  Detected JavaFX Ant API version 1.3
  Launching &lt;fx:jar&gt; task from C:\Program Files\Java\jdk1.8.0_71\jre\..\lib\ant-javafx.jar
  Warning: From JDK7u25 the Codebase manifest attribute should be used to restrict JAR repurposing.
           Please set manifest.custom.codebase property to override the current default non-secure value '*'.
  Launching &lt;fx:deploy&gt; task from C:\Program Files\Java\jdk1.8.0_71\jre\..\lib\ant-javafx.jar
  No base JDK. Package will use system JRE.
  No base JDK. Package will use system JRE.
  jfx-deployment-script:
  jfx-deployment:
  jar:
  Copying 13 files to C:\Users\Marco\Desktop\ConfiguradorDePC\dist\run150788111
  jfx-project-run:
  Executing C:\Users\Marco\Desktop\ConfiguradorDePC\dist\run150788111\ConfiguradorDePC.jar using platform C:\Program Files\Java\jdk1.8.0_71\jre/bin/java
  Exception in Application start method
  java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
          at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
  Caused by: java.lang.RuntimeException: Exception in Application start method
          at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
          at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
          at java.lang.Thread.run(Thread.java:745)
  Caused by: javafx.fxml.LoadException: 
  file:/C:/Users/Marco/Desktop/ConfiguradorDePC/dist/run150788111/ConfiguradorDePC.jar!/configuradordepc/view/View.fxml
  
          at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
          at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
          at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
          at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
          at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
          at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
          at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
          at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
          at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
          at configuradordepc.ConfiguradorDePC.start(ConfiguradorDePC.java:15)
          at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
          at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
          at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
          at java.security.AccessController.doPrivileged(Native Method)
          at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
          at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
          at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
          at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
          ... 1 more
  Caused by: java.lang.NullPointerException
          at configuradordepc.controller.ControladorView.initialize(ControladorView.java:75)
          at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
          ... 17 more
  Exception running application configuradordepc.ConfiguradorDePC
  Java Result: 1
  Deleting directory C:\Users\Marco\Desktop\ConfiguradorDePC\dist\run150788111
  jfxsa-run:
  BUILD SUCCESSFUL (total time: 3 seconds)
  </code></pre>
  
  <p>The FXML file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
    &lt;?import javafx.geometry.Insets?&gt;
    &lt;?import javafx.scene.control.Accordion?&gt;
    &lt;?import javafx.scene.control.Button?&gt;
    &lt;?import javafx.scene.control.Label?&gt;
    &lt;?import javafx.scene.control.Menu?&gt;
    &lt;?import javafx.scene.control.MenuBar?&gt;
    &lt;?import javafx.scene.control.MenuButton?&gt;
    &lt;?import javafx.scene.control.MenuItem?&gt;
    &lt;?import javafx.scene.control.TableColumn?&gt;
    &lt;?import javafx.scene.control.TableView?&gt;
    &lt;?import javafx.scene.control.TextField?&gt;
    &lt;?import javafx.scene.control.TitledPane?&gt;
    &lt;?import javafx.scene.layout.HBox?&gt;
    &lt;?import javafx.scene.layout.VBox?&gt;
  
    &lt;VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="configuradordepc.controller.ControladorView"&gt;
       &lt;children&gt;
          &lt;MenuBar&gt;
             &lt;menus&gt;
                &lt;Menu mnemonicParsing="false" text="Archivo"&gt;
                   &lt;items&gt;
                      &lt;MenuItem fx:id="mNew" mnemonicParsing="false" text="Nuevo" /&gt;
                      &lt;MenuItem fx:id="mOpen" mnemonicParsing="false" text="Abrir" /&gt;
                      &lt;MenuItem fx:id="mSave" mnemonicParsing="false" text="Guardar" /&gt;
                      &lt;MenuItem fx:id="mPrint" mnemonicParsing="false" text="Imprimir" /&gt;
                   &lt;/items&gt;
                &lt;/Menu&gt;
             &lt;/menus&gt;
          &lt;/MenuBar&gt;
          &lt;Accordion VBox.vgrow="ALWAYS"&gt;
             &lt;panes&gt;
                &lt;TitledPane animated="false" text="Nuevo PC"&gt;
                   &lt;content&gt;
                      &lt;VBox fx:id="vBox" spacing="10.0"&gt;
                         &lt;children&gt;
                            &lt;HBox spacing="10.0"&gt;
                               &lt;children&gt;
                                  &lt;TextField fx:id="tFSearch" HBox.hgrow="ALWAYS" /&gt;
                                  &lt;Button fx:id="bSearch" mnemonicParsing="false" onAction="#onSearch" text="Buscar" /&gt;
                               &lt;/children&gt;
                            &lt;/HBox&gt;
                            &lt;HBox spacing="10.0" VBox.vgrow="ALWAYS"&gt;
                               &lt;children&gt;
                                  &lt;VBox spacing="10.0"&gt;
                                     &lt;children&gt;
                                        &lt;MenuButton maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Categoría"&gt;
                                           &lt;items&gt;
                                              &lt;MenuItem fx:id="mMother" mnemonicParsing="false" text="Placas base" /&gt;
                                              &lt;MenuItem fx:id="mCPU" mnemonicParsing="false" text="Procesadores" /&gt;
                                              &lt;MenuItem fx:id="mRAM" mnemonicParsing="false" text="Memorias RAM" /&gt;
                                              &lt;MenuItem fx:id="mGPU" mnemonicParsing="false" text="Tarjetas gráficas" /&gt;
                                              &lt;MenuItem fx:id="mHardDrive" mnemonicParsing="false" text="Discos duros" /&gt;
                                              &lt;MenuItem fx:id="mCase" mnemonicParsing="false" text="Torres" /&gt;
                                              &lt;MenuItem fx:id="mKey" mnemonicParsing="false" text="Teclados" /&gt;
                                              &lt;MenuItem fx:id="mMouse" mnemonicParsing="false" text="Ratones" /&gt;
                                              &lt;MenuItem fx:id="mScreen" mnemonicParsing="false" text="Monitores" /&gt;
                                              &lt;MenuItem fx:id="mSpeak" mnemonicParsing="false" text="Altavoces" /&gt;
                                              &lt;MenuItem fx:id="mMulti" mnemonicParsing="false" text="Multilectores" /&gt;
                                              &lt;MenuItem fx:id="mDVD" mnemonicParsing="false" text="Grabadoras" /&gt;
                                              &lt;MenuItem fx:id="mFan" mnemonicParsing="false" text="Ventiladores" /&gt;
                                              &lt;MenuItem fx:id="mPower" mnemonicParsing="false" text="Fuente de alimentación" /&gt;
                                           &lt;/items&gt;
                                        &lt;/MenuButton&gt;
                                        &lt;HBox alignment="CENTER_LEFT"&gt;
                                           &lt;children&gt;
                                              &lt;Label prefWidth="87.0" text="Disponibilidad" /&gt;
                                              &lt;TextField fx:id="tFAvailable" HBox.hgrow="ALWAYS" /&gt;
                                           &lt;/children&gt;
                                        &lt;/HBox&gt;
                                        &lt;HBox alignment="CENTER_LEFT"&gt;
                                           &lt;children&gt;
                                              &lt;Label prefWidth="87.0" text="Precio Mín." /&gt;
                                              &lt;TextField fx:id="tFMin" HBox.hgrow="ALWAYS" /&gt;
                                           &lt;/children&gt;
                                        &lt;/HBox&gt;
                                        &lt;HBox alignment="CENTER_LEFT"&gt;
                                           &lt;children&gt;
                                              &lt;Label prefWidth="87.0" text="Precio Máx." /&gt;
                                              &lt;TextField fx:id="tFMax" HBox.hgrow="ALWAYS" /&gt;
                                           &lt;/children&gt;
                                        &lt;/HBox&gt;
                                     &lt;/children&gt;
                                  &lt;/VBox&gt;
                                  &lt;VBox alignment="CENTER" spacing="10.0" HBox.hgrow="ALWAYS"&gt;
                                     &lt;HBox.margin&gt;
                                        &lt;Insets /&gt;
                                     &lt;/HBox.margin&gt;
                                     &lt;children&gt;
                                        &lt;TableView VBox.vgrow="ALWAYS"&gt;
                                           &lt;columns&gt;
                                              &lt;TableColumn fx:id="nameItemColumn" editable="false" prefWidth="75.0" sortable="false" text="Nombre" /&gt;
                                              &lt;TableColumn fx:id="priceColumn" editable="false" prefWidth="75.0" sortable="false" text="Precio" /&gt;
                                              &lt;TableColumn fx:id="availableColumn" editable="false" prefWidth="75.0" sortable="false" text="Disponibilidad" /&gt;
                                           &lt;/columns&gt;
                                           &lt;columnResizePolicy&gt;
                                              &lt;TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /&gt;
                                           &lt;/columnResizePolicy&gt;
                                        &lt;/TableView&gt;
                                        &lt;Button fx:id="bAdd" mnemonicParsing="false" onAction="#onAdd" text="Añadir" /&gt;
                                     &lt;/children&gt;
                                  &lt;/VBox&gt;
                                  &lt;VBox spacing="10.0" HBox.hgrow="ALWAYS"&gt;
                                     &lt;children&gt;
                                        &lt;TableView VBox.vgrow="ALWAYS"&gt;
                                           &lt;columns&gt;
                                              &lt;TableColumn fx:id="nameBudgetColumn" editable="false" prefWidth="75.0" sortable="false" text="Nombre" /&gt;
                                              &lt;TableColumn fx:id="outTaxColumn" editable="false" prefWidth="75.0" sortable="false" text="Sin IVA" /&gt;
                                              &lt;TableColumn fx:id="inTaxColumn" editable="false" prefWidth="75.0" sortable="false" text="Con IVA" /&gt;
                                              &lt;TableColumn fx:id="quantityColumn" prefWidth="75.0" sortable="false" text="Cantidad" /&gt;
                                           &lt;/columns&gt;
                                           &lt;columnResizePolicy&gt;
                                              &lt;TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /&gt;
                                           &lt;/columnResizePolicy&gt;
                                        &lt;/TableView&gt;
                                        &lt;HBox alignment="CENTER" spacing="10.0"&gt;
                                           &lt;children&gt;
                                              &lt;Button fx:id="bDelete" mnemonicParsing="false" onAction="#onDelete" text="Eliminar" /&gt;
                                              &lt;Button fx:id="bClean" mnemonicParsing="false" onAction="#onClean" text="Limpiar" /&gt;
                                           &lt;/children&gt;
                                        &lt;/HBox&gt;
                                     &lt;/children&gt;
                                  &lt;/VBox&gt;
                               &lt;/children&gt;
                            &lt;/HBox&gt;
                         &lt;/children&gt;
                         &lt;padding&gt;
                            &lt;Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /&gt;
                         &lt;/padding&gt;
                      &lt;/VBox&gt;
                   &lt;/content&gt;
                &lt;/TitledPane&gt;
                &lt;TitledPane animated="false" text="Configuraciones" /&gt;
             &lt;/panes&gt;
          &lt;/Accordion&gt;
       &lt;/children&gt;
    &lt;/VBox&gt;
  </code></pre>