Getting text from TextArea in a GridPane in JavaFX
<p>I have a project in which I ask a user what type of electronic devices they use to tell them how many solar panels and batteries they need. </p>

<p>To collect information, I use a gridPane with three columns, in which there are TextArea, and a variable amount of rows. I need to collect the information in the second and third row of the gridPane.</p>

<p>I use the following method which I found on another question asked here.</p>

<pre><code>private void calculer(ActionEvent event)
{
    double ampApp = 0;
    double heureApp = 0;
    double wattTotal = 0;
    double nbJourAuto;
    double heureSoleil;
    int nbPanneau;
    int nbBatterie;
    String stringTemp;

    for(int i =1; i &lt; rangee; i++)
    {
        stringTemp = getNodeByRowColumnIndex( i, 1, gridApp).toString();
        ampApp += parseDouble(stringTemp);
    }

    for(int i =1; i &lt; rangee; i++)
    {
        stringTemp = getNodeByRowColumnIndex(i, 2, gridApp).toString();
        heureApp += parseDouble(stringTemp);
    }
</code></pre>

<p>(it's only the first part of the method, I know there is a missing "}")</p>

<p>And here is the getNodeByRowColumnIndex code:</p>

<pre><code>public Node getNodeByRowColumnIndex( final int row, final int column, GridPane gridPane) {
   Node result = null;
   ObservableList&lt;Node&gt; childrens = gridPane.getChildren();
   for(Node node : childrens) 
   {
        if(gridPane.getRowIndex(node) == row &amp;&amp; gridPane.getColumnIndex(node) == column) 
        {
           result = node;
           break;
        }
   }
   return result;
}
</code></pre>

<p>I tried this method, but keep getting java.lang.NullPointerException</p>

<p>Does anyone knows why and how to solve this issues?</p>

<p>Edit :</p>

<p>As requested here's the stack trace</p>

<pre><code>Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: 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:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 48 more
Caused by: java.lang.NullPointerException
at systemesolaire.FXMLDocumentController.getNodeByRowColumnIndex(FXMLDocumentController.java:111)
at systemesolaire.FXMLDocumentController.calculer(FXMLDocumentController.java:81)
... 58 more
</code></pre>

<p>and here's how I intialize my children (I used SceneBuilder so here is the FXML file)</p>

<pre><code>&lt;content&gt;
        &lt;GridPane fx:id="gridApp" prefHeight="141.0" prefWidth="452.0"&gt;
           &lt;columnConstraints&gt;
              &lt;ColumnConstraints hgrow="SOMETIMES" maxWidth="226.0" minWidth="10.0" prefWidth="226.0" /&gt;
              &lt;ColumnConstraints hgrow="SOMETIMES" maxWidth="146.0" minWidth="10.0" prefWidth="123.0" /&gt;
              &lt;ColumnConstraints hgrow="SOMETIMES" maxWidth="113.0" minWidth="10.0" prefWidth="103.0" /&gt;
           &lt;/columnConstraints&gt;
           &lt;rowConstraints&gt;
              &lt;RowConstraints minHeight="40.0" prefHeight="40.0" vgrow="NEVER" /&gt;
              &lt;RowConstraints minHeight="40.0" prefHeight="40.0" vgrow="NEVER" /&gt;
              &lt;RowConstraints minHeight="40.0" prefHeight="40.0" vgrow="NEVER" /&gt;
           &lt;/rowConstraints&gt;
           &lt;children&gt;
              &lt;Label text="  Nom de l'appareil"&gt;
                 &lt;font&gt;
                    &lt;Font name="Anke" size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Label&gt;
              &lt;Label text="Ampérage" GridPane.columnIndex="1"&gt;
                 &lt;font&gt;
                    &lt;Font name="Anke" size="14.0" /&gt;
                 &lt;/font&gt;
              &lt;/Label&gt;
              &lt;Label text="Heures utilisation" GridPane.columnIndex="2"&gt;
                 &lt;font&gt;
                    &lt;Font name="Anke" size="13.0" /&gt;
                 &lt;/font&gt;
              &lt;/Label&gt;
              &lt;TextArea prefHeight="200.0" prefWidth="200.0" promptText="Nom" GridPane.rowIndex="1" /&gt;
              &lt;TextArea prefHeight="200.0" prefWidth="200.0" promptText="Amp" GridPane.columnIndex="1" GridPane.rowIndex="1" /&gt;
              &lt;TextArea prefHeight="200.0" prefWidth="200.0" promptText="Heure" GridPane.columnIndex="2" GridPane.rowIndex="1" /&gt;
              &lt;TextArea prefHeight="200.0" prefWidth="200.0" promptText="Nom" GridPane.rowIndex="2" /&gt;
              &lt;TextArea prefHeight="200.0" prefWidth="200.0" promptText="Amp" GridPane.columnIndex="1" GridPane.rowIndex="2" /&gt;
              &lt;TextArea prefHeight="200.0" prefWidth="200.0" promptText="Heure" GridPane.columnIndex="2" GridPane.rowIndex="2" /&gt;
           &lt;/children&gt;
        &lt;/GridPane&gt;
     &lt;/content&gt;
</code></pre>

<p>And here is How I add a row to my gridPane</p>

<pre><code> @FXML
private void ajouteRangee(ActionEvent event) 
{

   TextArea nom =  new TextArea();
   TextArea amp = new TextArea();
   TextArea heure = new TextArea();



   nom.setPromptText("Nom");
   amp.setPromptText("Amp");
   heure.setPromptText("heure");


   gridApp.addRow(rangee, nom, amp, heure);
   gridApp.layout();
   rangee++;

}
</code></pre>