0

I am trying to get a button click to add ints that are typed into text boxes by users into another textbox. Im using FXML and I have set the on action to calculateTotal(). When I click the button when it is running I get a null pointer excpetion though on the line

int sal1 = Integer.parseInt(sale1.getText());

Here is the rest of the code. The line the error is on is toward the bottom in calculateTotal().

package taxerfxml;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javax.swing.JComboBox;
import static sun.misc.Signal.handle;


/**
 *
 * @author 
 */
public class FXMLDocumentController implements Initializable  {
    ObservableList<String> comboBoxList = FXCollections.observableArrayList("Ccosta", "Alam", "Sclara", "Smateo", "Sf", "Marin", "Sonoma", "Napa", "Solono");

//fxml combo boxes
    @FXML
    private ComboBox comboBox1;
    @FXML
    private ComboBox comboBox2;
    @FXML
    private ComboBox comboBox3;
    @FXML
    private ComboBox comboBox4;
    @FXML
    private ComboBox comboBox5;
    @FXML
    private ComboBox comboBox6;
    @FXML
    private ComboBox comboBox7;
    @FXML
    private ComboBox comboBox8;
    @FXML
    private ComboBox comboBox9;
    @FXML
    private ComboBox comboBox10;
    @FXML
    private ComboBox comboBox11;
    @FXML
    private ComboBox comboBox12;

//fxml labels
    @FXML
    private Label sale;    
    @FXML
    private Label tax;
    @FXML
    private Label county;  
    @FXML
    private Label freight;
    @FXML
    private Label labor;
    @FXML
    private Label cost;
    @FXML
    private Label profit;
    @FXML
    private Label customer;

    // fxml customer textfields
    @FXML
    private TextField customer1;
    @FXML
    private TextField customer2;
    @FXML
    private TextField customer3;
    @FXML
    private TextField customer4;
    @FXML
    private TextField customer5;
    @FXML
    private TextField customer6;
    @FXML
    private TextField customer7;
    @FXML
    private TextField customer8;
    @FXML
    private TextField customer9;
    @FXML
    private TextField customer10;
    @FXML
    private TextField customer11;
    @FXML
    private TextField customer12;

    //fxml sale textfields

    @FXML
    private TextField sale1;
    @FXML
    private TextField sale2;
    @FXML
    private TextField sale3;
    @FXML
    private TextField sale4;
    @FXML
    private TextField sale5;
    @FXML
    private TextField sale6;
    @FXML
    private TextField sale7;
    @FXML
    private TextField sale8;
    @FXML
    private TextField sale9;
    @FXML
    private TextField sale10;
    @FXML
    private TextField sale11;
    @FXML
    private TextField sale12;

    //fxml tax textfields 

    @FXML
    private TextField tax1;
    @FXML
    private TextField tax2;
    @FXML
    private TextField tax3;
    @FXML
    private TextField tax4;
    @FXML
    private TextField tax5;
    @FXML
    private TextField tax6;
    @FXML
    private TextField tax7;
    @FXML
    private TextField tax8;
    @FXML
    private TextField tax9;
    @FXML
    private TextField tax10;
    @FXML
    private TextField tax11;
    @FXML
    private TextField tax12;

    //fxml freight textfields
    @FXML
    private TextField freight1;
    @FXML
    private TextField freight2;
    @FXML
    private TextField freight3;
    @FXML
    private TextField freight4;
    @FXML
    private TextField freight5;
    @FXML
    private TextField freight6;
    @FXML
    private TextField freight7;
    @FXML
    private TextField freight8;
    @FXML
    private TextField freight9;
    @FXML
    private TextField freight10;
    @FXML
    private TextField freight11;
    @FXML
    private TextField freight12;

    //fxml labor textfields
    @FXML
    private TextField labor1;
    @FXML
    private TextField labor2;
    @FXML
    private TextField labor3;
    @FXML
    private TextField labor4;
    @FXML
    private TextField labor5;
    @FXML
    private TextField labor6;
    @FXML
    private TextField labor7;
    @FXML
    private TextField labor8;
    @FXML
    private TextField labor9;
    @FXML
    private TextField labor10;
    @FXML
    private TextField labor11;
    @FXML
    private TextField labor12;

    //fxml cost textfields
    @FXML
    private TextField cost1;
    @FXML
    private TextField cost2;
    @FXML
    private TextField cost3;
    @FXML
    private TextField cost4;
    @FXML
    private TextField cost5;
    @FXML
    private TextField cost6;
    @FXML
    private TextField cost7;
    @FXML
    private TextField cost8;
    @FXML
    private TextField cost9;
    @FXML
    private TextField cost10;
    @FXML
    private TextField cost11;
    @FXML
    private TextField cost12;

    //fxml profit textfields
    @FXML
    private TextField profit1;
    @FXML
    private TextField profit2;
    @FXML
    private TextField profit3;
    @FXML
    private TextField profit4;
    @FXML
    private TextField profit5;
    @FXML
    private TextField profit6;
    @FXML
    private TextField profit7;
    @FXML
    private TextField profit8;
    @FXML
    private TextField profit9;
    @FXML
    private TextField profit10;
    @FXML
    private TextField profit11;
    @FXML
    private TextField profit12;

    //fxml button calculate   
   @FXML
    private Button calculate;




    @Override
    public void initialize(URL url, ResourceBundle rb) {



         //initialize combobox variables
        comboBox1.setValue("County");
        comboBox1.setItems(comboBoxList);

        comboBox2.setValue("County");
        comboBox2.setItems(comboBoxList);

        comboBox3.setValue("County");
        comboBox3.setItems(comboBoxList);

        comboBox4.setValue("County");
        comboBox4.setItems(comboBoxList);

        comboBox5.setValue("County");
        comboBox5.setItems(comboBoxList);

        comboBox6.setValue("County");
        comboBox6.setItems(comboBoxList);

        comboBox7.setValue("County");
        comboBox7.setItems(comboBoxList);

        comboBox8.setValue("County");
        comboBox8.setItems(comboBoxList);

        comboBox9.setValue("County");
        comboBox9.setItems(comboBoxList);

        comboBox10.setValue("County");
        comboBox10.setItems(comboBoxList);

        comboBox11.setValue("County");
        comboBox11.setItems(comboBoxList);

        comboBox12.setValue("County");
        comboBox12.setItems(comboBoxList);
    }

        @FXML
        public void calculateTotal(ActionEvent event){

        //add values put into textfields  
       // calculateTotal.setOnAction(new EventHandler<ActionEvent>() {
       // if(event.getSource()==calculateTotal){

        //row1
        int sal1 = Integer.parseInt(sale1.getText());
        int taxx1 = Integer.parseInt(tax1.getText());
        int frei1 = Integer.parseInt(freight1.getText());
        int lab1 = Integer.parseInt(labor1.getText());
        int cos1 = Integer.parseInt(cost1.getText());        
        int result1 = sal1 + taxx1 + frei1 + lab1 + cos1;
        profit1.setText(profit1.getText()+result1);


        //row2
        int sal2 = Integer.parseInt(sale2.getText());
        int taxx2 = Integer.parseInt(tax2.getText());
        int frei2 = Integer.parseInt(freight2.getText());
        int lab2 = Integer.parseInt(labor2.getText());
        int cos2 = Integer.parseInt(cost2.getText());        
        int result2 = sal2 + taxx2 + frei2 + lab2 + cos2;
        profit2.setText(profit2.getText()+result2);     

        //row3
        int sal3 = Integer.parseInt(sale3.getText());
        int taxx3 = Integer.parseInt(tax3.getText());
        int frei3 = Integer.parseInt(freight3.getText());
        int lab3 = Integer.parseInt(labor3.getText());
        int cos3 = Integer.parseInt(cost3.getText());        
        int result3 = sal3 + taxx3 + frei3 + lab3 + cos3;
        profit3.setText(profit3.getText()+result3);

        //row4
        int sal4 = Integer.parseInt(sale4.getText());
        int taxx4 = Integer.parseInt(tax4.getText());
        int frei4 = Integer.parseInt(freight4.getText());
        int lab4 = Integer.parseInt(labor4.getText());
        int cos4 = Integer.parseInt(cost4.getText());        
        int result4 = sal4 + taxx4 + frei4 + lab4 + cos4;
        profit4.setText(profit4.getText()+result4);

        //row5
        int sal5 = Integer.parseInt(sale5.getText());
        int taxx5 = Integer.parseInt(tax5.getText());
        int frei5 = Integer.parseInt(freight5.getText());
        int lab5 = Integer.parseInt(labor5.getText());
        int cos5 = Integer.parseInt(cost5.getText());        
        int result5 = sal5 + taxx5 + frei5 + lab5 + cos5;
        profit5.setText(profit5.getText()+result5);

        //row6
        int sal6 = Integer.parseInt(sale6.getText());
        int taxx6 = Integer.parseInt(tax6.getText());
        int frei6 = Integer.parseInt(freight6.getText());
        int lab6 = Integer.parseInt(labor6.getText());
        int cos6 = Integer.parseInt(cost6.getText());        
        int result6 = sal6 + taxx6 + frei6 + lab6 + cos6;
        profit6.setText(profit6.getText()+result6);

        //row7
        int sal7 = Integer.parseInt(sale7.getText());
        int taxx7 = Integer.parseInt(tax7.getText());
        int frei7 = Integer.parseInt(freight7.getText());
        int lab7 = Integer.parseInt(labor7.getText());
        int cos7 = Integer.parseInt(cost7.getText());        
        int result7 = sal7 + taxx7 + frei7 + lab7 + cos7;
        profit7.setText(profit7.getText()+result7);

        //row8
        int sal8 = Integer.parseInt(sale8.getText());
        int taxx8 = Integer.parseInt(tax8.getText());
        int frei8 = Integer.parseInt(freight8.getText());
        int lab8 = Integer.parseInt(labor8.getText());
        int cos8 = Integer.parseInt(cost8.getText());        
        int result8 = sal8 + taxx8 + frei8 + lab8 + cos8;
        profit8.setText(profit8.getText()+result8);

        //row9
        int sal9 = Integer.parseInt(sale9.getText());
        int taxx9 = Integer.parseInt(tax9.getText());
        int frei9 = Integer.parseInt(freight9.getText());
        int lab9 = Integer.parseInt(labor9.getText());
        int cos9 = Integer.parseInt(cost9.getText());        
        int result9 = sal9 + taxx9 + frei9 + lab9 + cos9;
        profit9.setText(profit9.getText()+result9);

        //row10
        int sal10 = Integer.parseInt(sale10.getText());
        int taxx10 = Integer.parseInt(tax10.getText());
        int frei10 = Integer.parseInt(freight10.getText());
        int lab10 = Integer.parseInt(labor10.getText());
        int cos10 = Integer.parseInt(cost10.getText());        
        int result10 = sal10 + taxx10 + frei10 + lab10 + cos10;
        profit10.setText(profit10.getText()+result10);

        //row11
        int sal11 = Integer.parseInt(sale11.getText());
        int taxx11 = Integer.parseInt(tax11.getText());
        int frei11 = Integer.parseInt(freight11.getText());
        int lab11 = Integer.parseInt(labor11.getText());
        int cos11 = Integer.parseInt(cost11.getText());        
        int result11 = sal11 + taxx11 + frei11 + lab11 + cos11;
        profit11.setText(profit11.getText()+result11);

        //row12
        int sal12 = Integer.parseInt(sale12.getText());
        int taxx12 = Integer.parseInt(tax12.getText());
        int frei12 = Integer.parseInt(freight12.getText());
        int lab12 = Integer.parseInt(labor12.getText());
        int cos12 = Integer.parseInt(cost12.getText());        
        int result12 = sal12 + taxx12 + frei12 + lab12 + cos12;
        profit12.setText(profit12.getText()+result12);




        }


}

Here is my fxml file. the button is after the comboboxes

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.shape.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="615.0" prefWidth="1070.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="taxerfxml.FXMLDocumentController">
    <children>
      <Accordion layoutX="14.0" layoutY="14.0" />
      <Label layoutX="238.0" layoutY="6.0" text="Sale" />
      <Label layoutX="358.0" layoutY="6.0" text="Tax" />
      <Label layoutX="491.0" layoutY="6.0" text="County" />
      <Label layoutX="622.0" layoutY="6.0" text="Freight" />
      <Label layoutX="741.0" layoutY="6.0" text="Labor" />
      <Label layoutX="857.0" layoutY="6.0" text="Cost" />
      <Label layoutX="994.0" layoutY="6.0" text="Profit" />
      <Label layoutX="14.0" layoutY="6.0" text="Customer" />
      <TextField layoutY="81.0" text="Customer 1" />
      <TextField layoutY="125.0" text="Customer 2" />
      <TextField layoutY="168.0" text="Customer 3" />
      <TextField layoutY="212.0" text="Customer 4" />
      <TextField layoutY="256.0" text="Customer 5" />
      <TextField layoutY="303.0" text="Customer 6" />
      <TextField layoutY="346.0" text="Customer 7" />
      <TextField layoutY="394.0" text="Customer 8" />
      <TextField layoutY="439.0" text="Customer 9" />
      <TextField layoutY="485.0" text="Customer 10" />
      <TextField layoutY="537.0" text="Customer 11" />
      <TextField layoutY="582.0" text="Customer 12" />
      <TextField layoutX="205.0" layoutY="83.0" prefHeight="25.0" prefWidth="88.0" text="Sale1" />
      <TextField layoutX="205.0" layoutY="127.0" prefHeight="25.0" prefWidth="88.0" text="Sale2" />
      <TextField layoutX="205.0" layoutY="170.0" prefHeight="25.0" prefWidth="88.0" text="Sale3" />
      <TextField layoutX="205.0" layoutY="214.0" prefHeight="25.0" prefWidth="88.0" text="Sale4" />
      <TextField layoutX="205.0" layoutY="258.0" prefHeight="25.0" prefWidth="88.0" text="Sale5" />
      <TextField layoutX="205.0" layoutY="305.0" prefHeight="25.0" prefWidth="88.0" text="Sale6" />
      <TextField layoutX="205.0" layoutY="348.0" prefHeight="25.0" prefWidth="88.0" text="Sale7" />
      <TextField layoutX="205.0" layoutY="396.0" prefHeight="25.0" prefWidth="88.0" text="Sale8" />
      <TextField layoutX="205.0" layoutY="441.0" prefHeight="25.0" prefWidth="88.0" text="Sale9" />
      <TextField layoutX="205.0" layoutY="487.0" prefHeight="25.0" prefWidth="88.0" text="Sale10" />
      <TextField layoutX="205.0" layoutY="539.0" prefHeight="25.0" prefWidth="88.0" text="Sale11" />
      <TextField layoutX="205.0" layoutY="584.0" prefHeight="25.0" prefWidth="88.0" text="Sale12" />
      <TextField layoutX="319.0" layoutY="83.0" prefHeight="25.0" prefWidth="97.0" text="Tax1" />
      <TextField layoutX="319.0" layoutY="127.0" prefHeight="25.0" prefWidth="97.0" text="Tax2" />
      <TextField layoutX="319.0" layoutY="168.0" prefHeight="25.0" prefWidth="97.0" text="Tax3" />
      <TextField layoutX="319.0" layoutY="214.0" prefHeight="25.0" prefWidth="97.0" text="Tax4" />
      <TextField layoutX="319.0" layoutY="258.0" prefHeight="25.0" prefWidth="97.0" text="Tax5" />
      <TextField layoutX="319.0" layoutY="305.0" prefHeight="25.0" prefWidth="97.0" text="Tax6" />
      <TextField layoutX="319.0" layoutY="348.0" prefHeight="25.0" prefWidth="97.0" text="Tax7" />
      <TextField layoutX="319.0" layoutY="394.0" prefHeight="25.0" prefWidth="97.0" text="Tax8" />
      <TextField layoutX="319.0" layoutY="441.0" prefHeight="25.0" prefWidth="97.0" text="Tax9" />
      <TextField layoutX="319.0" layoutY="487.0" prefHeight="25.0" prefWidth="97.0" text="Tax10" />
      <TextField layoutX="319.0" layoutY="539.0" prefHeight="25.0" prefWidth="97.0" text="Tax11" />
      <TextField layoutX="319.0" layoutY="584.0" prefHeight="25.0" prefWidth="97.0" text="Tax12" />
      <ComboBox id="comboBox1" fx:id="comboBox1" layoutX="466.0" layoutY="77.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <ComboBox id="comboBox2" fx:id="comboBox2" layoutX="466.0" layoutY="120.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" /> 
      <ComboBox id="comboBox3" fx:id="comboBox3" layoutX="466.0" layoutY="166.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <ComboBox id="comboBox4" fx:id="comboBox4" layoutX="466.0" layoutY="210.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <ComboBox id="comboBox5" fx:id="comboBox5" layoutX="466.0" layoutY="254.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <ComboBox id="comboBox6" fx:id="comboBox6" layoutX="466.0" layoutY="301.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <ComboBox id="comboBox7" fx:id="comboBox7" layoutX="466.0" layoutY="344.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <ComboBox id="comboBox8" fx:id="comboBox8" layoutX="466.0" layoutY="392.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <ComboBox id="comboBox9" fx:id="comboBox9" layoutX="466.0" layoutY="437.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <ComboBox id="comboBox10" fx:id="comboBox10" layoutX="466.0" layoutY="483.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <ComboBox id="comboBox11" fx:id="comboBox11" layoutX="466.0" layoutY="533.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <ComboBox id="comboBox12" fx:id="comboBox12" layoutX="466.0" layoutY="580.0" prefHeight="34.0" prefWidth="88.0" promptText="Choose" />
      <Button fx:id="calculate" layoutX="976.0" layoutY="23.0" mnemonicParsing="false" onAction="#calculateTotal" text="Calculate" />
      <TextField layoutX="597.0" layoutY="81.0" prefHeight="17.0" prefWidth="88.0" text="Freight1" />
      <TextField layoutX="597.0" layoutY="125.0" prefHeight="17.0" prefWidth="88.0" text="Freight2" />
      <TextField layoutX="597.0" layoutY="171.0" prefHeight="17.0" prefWidth="88.0" text="Freight3" />
      <TextField layoutX="597.0" layoutY="212.0" prefHeight="17.0" prefWidth="88.0" text="Freight4" />
      <TextField layoutX="597.0" layoutY="256.0" prefHeight="17.0" prefWidth="88.0" text="Freight5" />
      <TextField layoutX="597.0" layoutY="303.0" prefHeight="17.0" prefWidth="88.0" text="Freight6" />
      <TextField layoutX="597.0" layoutY="346.0" prefHeight="17.0" prefWidth="88.0" text="Freight7" />
      <TextField layoutX="597.0" layoutY="396.0" prefHeight="17.0" prefWidth="88.0" text="Freight8" />
      <TextField layoutX="597.0" layoutY="439.0" prefHeight="17.0" prefWidth="88.0" text="Freight9" />
      <TextField layoutX="597.0" layoutY="485.0" prefHeight="17.0" prefWidth="88.0" text="Freight10" />
      <TextField layoutX="597.0" layoutY="537.0" prefHeight="17.0" prefWidth="88.0" text="Freight11" />
      <TextField layoutX="597.0" layoutY="582.0" prefHeight="17.0" prefWidth="88.0" text="Freight12" />
      <TextField layoutX="712.0" layoutY="81.0" prefHeight="25.0" prefWidth="88.0" text="Labor1" />
      <TextField layoutX="712.0" layoutY="125.0" prefHeight="25.0" prefWidth="88.0" text="Labor2" />
      <TextField layoutX="712.0" layoutY="171.0" prefHeight="25.0" prefWidth="88.0" text="Labor3" />
      <TextField layoutX="713.0" layoutY="212.0" prefHeight="25.0" prefWidth="88.0" text="Labor4" />
      <TextField layoutX="713.0" layoutY="256.0" prefHeight="25.0" prefWidth="88.0" text="Labor5" />
      <TextField layoutX="713.0" layoutY="303.0" prefHeight="25.0" prefWidth="88.0" text="Labor6" />
      <TextField layoutX="713.0" layoutY="346.0" prefHeight="25.0" prefWidth="88.0" text="Labor7" />
      <TextField layoutX="713.0" layoutY="397.0" prefHeight="25.0" prefWidth="88.0" text="Labor8" />
      <TextField layoutX="713.0" layoutY="439.0" prefHeight="25.0" prefWidth="88.0" text="Labor9" />
      <TextField layoutX="713.0" layoutY="485.0" prefHeight="25.0" prefWidth="88.0" text="Labor10" />
      <TextField layoutX="713.0" layoutY="537.0" prefHeight="25.0" prefWidth="88.0" text="Labor11" />
      <TextField layoutX="713.0" layoutY="582.0" prefHeight="25.0" prefWidth="88.0" text="Labor12" />
      <TextField layoutX="825.0" layoutY="82.0" prefHeight="25.0" prefWidth="88.0" text="Cost1" />
      <TextField layoutX="825.0" layoutY="125.0" prefHeight="25.0" prefWidth="88.0" text="Cost2" />
      <TextField layoutX="825.0" layoutY="170.0" prefHeight="25.0" prefWidth="88.0" text="Cost3" />
      <TextField layoutX="825.0" layoutY="212.0" prefHeight="25.0" prefWidth="88.0" text="Cost4" />
      <TextField layoutX="825.0" layoutY="256.0" prefHeight="25.0" prefWidth="88.0" text="Cost5" />
      <TextField layoutX="825.0" layoutY="303.0" prefHeight="25.0" prefWidth="88.0" text="Cost6" />
      <TextField layoutX="825.0" layoutY="346.0" prefHeight="25.0" prefWidth="88.0" text="Cost7" />
      <TextField layoutX="825.0" layoutY="396.0" prefHeight="25.0" prefWidth="88.0" text="Cost8" />
      <TextField layoutX="825.0" layoutY="439.0" prefHeight="25.0" prefWidth="88.0" text="Cost9" />
      <TextField layoutX="825.0" layoutY="485.0" prefHeight="25.0" prefWidth="88.0" text="Cost10" />
      <TextField layoutX="825.0" layoutY="537.0" prefHeight="25.0" prefWidth="88.0" text="Cost11" />
      <TextField layoutX="825.0" layoutY="582.0" prefHeight="25.0" prefWidth="88.0" text="Cost12" />
      <TextField layoutX="952.0" layoutY="81.0" prefHeight="25.0" prefWidth="114.0" text="Profit1" />
      <TextField layoutX="952.0" layoutY="125.0" prefHeight="25.0" prefWidth="114.0" text="Profit2" />
      <TextField layoutX="952.0" layoutY="168.0" prefHeight="25.0" prefWidth="114.0" text="Profit3" />
      <TextField layoutX="952.0" layoutY="212.0" prefHeight="25.0" prefWidth="114.0" text="Profit4" />
      <TextField layoutX="952.0" layoutY="256.0" prefHeight="25.0" prefWidth="114.0" text="Profit5" />
      <TextField layoutX="952.0" layoutY="303.0" prefHeight="25.0" prefWidth="114.0" text="Profit6" />
      <TextField layoutX="952.0" layoutY="346.0" prefHeight="25.0" prefWidth="114.0" text="Profit7" />
      <TextField layoutX="952.0" layoutY="394.0" prefHeight="25.0" prefWidth="114.0" text="Profit8" />
      <TextField layoutX="952.0" layoutY="439.0" prefHeight="25.0" prefWidth="114.0" text="Profit9" />
      <TextField layoutX="952.0" layoutY="485.0" prefHeight="25.0" prefWidth="114.0" text="Profit10" />
      <TextField layoutX="952.0" layoutY="537.0" prefHeight="25.0" prefWidth="114.0" text="Profit11" />
      <TextField layoutX="952.0" layoutY="582.0" prefHeight="25.0" prefWidth="114.0" text="Profit12" />

    </children>
</AnchorPane>
bills
  • 59
  • 9
  • that is because sale1 is null, are you sure you have a label named so in the xml doc? – ΦXocę 웃 Пepeúpa ツ May 04 '17 at 06:22
  • @ΦXocę웃Пepeúpaツ I added the fxml file. What do you mean sale1 is null? sorry im new to this – bills May 04 '17 at 06:29
  • To understand why your code doesn't work, think about the fact that the text fields are set up in the FXML file, but there is no possible way that the controller has of knowing *which* of the (enormous number of) text fields is `sale1`. To understand what a null pointer exception is, read http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it. To understand how to fix this particular NPE, read any intro on FXML/controllers, e.g. http://stackoverflow.com/documentation/javafx/1580/fxml-and-controllers/5125/example-fxml#t=201705041156368117264 – James_D May 04 '17 at 11:57

2 Answers2

1

You are getting Null Pointer Exception because you haven't initialize sale1 you have only decclared it. for better understanding on Null pointer Exception follow the link below: https://stackoverflow.com/a/218510/3420973

Community
  • 1
  • 1
-1

I would assume you receive this error because the text you have gotten with the getText() function is not able to be converted to a integer.

You could put a try statement around it.

For example

try { //it will attempt to convert the text
... your code
} catch (Exception e) { // if it fails the following code will happen
... error response code
} 

EDIT:

It seems your problem is actually not initialized TextFields. Here is a post that may help How can a textfield from fxml file be updated by setText in java file?

And here is another How can I fix a NullPointerException when interacting with FXML elements in the start method?

Community
  • 1
  • 1
JFreeman
  • 974
  • 1
  • 10
  • 26
  • It is *always* a mistake to explicitly initialize fields that are annotated `@FXML`. This code would get rid of the NPE, but it would not have the desired effect because it would not call methods on the text field defined in the FXML file. – James_D May 04 '17 at 11:59
  • Yes I have edited my post because i misunderstood that he was using `FXML` Thank you! – JFreeman May 05 '17 at 02:52
  • I guess the 120 lines of FXML code and *over 100 `@FXML`* annotations are pretty easy to miss.... Its also really a mistake to catch `NullPointerException`s, as those really represent non-recoverable errors that are, certainly in this case, programming errors. The post you linked appears to be completely irrelevant. – James_D May 05 '17 at 02:59