0

Im writing a program that adds together numbers that are put into text boxes. The output should go in a textbox at the end of each row of textboxes when a button is pushed. Nothing is happening though. Is there something im missing? Here is the code I have. The method to handle the event and add each text box is at the bottom

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;


/**
 *
 * 
 */
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 calculateTotal;



    @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);
    }


        public void calculate(ActionEvent event){
        //add values put into textfields  
        calculateTotal.setOnAction((EventHandler<ActionEvent>) (event));{



        //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);
    }   

        }


}










    /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
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;

here is my updated file. Im now getting a nullPointerException from the first line in calculateTotal()

/**
 *
 * @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 the fxml file that i shouldve included. I cut it down to where it really only shows the button declaration becuase thats where the problem is coming from.

      <Button fx:id="calculate" layoutX="976.0" layoutY="23.0" mnemonicParsing="false" onAction="#calculateTotal" text="Calculate" />
bills
  • 59
  • 8
  • To find out if the button is actually firing you should simply put a System.out.println("you just pressed the button"); inside your calculateTotal handler at the top. If you see this code after pressing the button, you know that the button is firing and that your problem lies elsewhere. To try to see if the code is throwing an uncaught error, put all of the code in a try block then in your catch box use Exception ex and print the ex.toString(); – Sedrick May 04 '17 at 13:51

1 Answers1

-2

You don't define a EventHandler for the action, try this code snippets:

    calculateTotal.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            // 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);
            ......
        }
    });
Dave Pateral
  • 1,362
  • 12
  • 20
  • I just tried this but on the very last bracket im getting an error that says "reached end of file while parsing". Any idea why? – bills May 04 '17 at 02:48
  • ok i forgot a bracket at the end of the file. I fixed that error. But when I added the event handle, nothing happened still when i press the button – bills May 04 '17 at 02:52
  • Add @FXML annotation for calculate() method,if it does not work copy that code snippets into initialize() method. – Dave Pateral May 04 '17 at 03:09
  • You are using FXML. You should define an onAction event through FXML like in the question comment I linked as a potential duplicate on your previous question that I can no longer find. I'll link it again http://stackoverflow.com/questions/17344698/java-fx-fxml-on-action. Read the documentation if you do not understand: https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html#controller_method_event_handlers. You would never define a new setOnAction event handler within an existing event handler linked to FXML. – jewelsea May 04 '17 at 03:13
  • @DavePateral I tried adding the annotation but im still not getting anything to happen. Do i need to add something to my main method in the other file? or is there something else wrong? – bills May 04 '17 at 04:03
  • @jewelsea I read through the documentation but im still confused on what im missing or doing wrong – bills May 04 '17 at 04:04
  • Probably you are missing the onAction attribute in the FXML. But it is hard to say because you don't provide the FXML in a [mcve]. Anyway calling setOnAction from within the action handler as you have in the code in your question is wrong. Also if any of your code throws an exception such as a parsing exception for an Integer, that you don't handle, then it probably won't work as you expect either. – jewelsea May 04 '17 at 05:44
  • @jewelsea I added my update and also the line from the fxml file that shows the button. Im getting a nullpointerexception on the first line in calculateTotal though. – bills May 04 '17 at 06:26
  • Then sale1 is null or sale1.getText() returns null. If sale1 is null then probably you haven't correctly defined the fx:id for in your FXML. If sale.getText() is null then you probably shouldn't pass it to Integer.parseInt. Read http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it, note you do not have to set sale1 = new TextField() to fix the issue as sale1 should be correctly injected as long as your FXML is correct. – jewelsea May 04 '17 at 06:45