0

i need some help. I want to transfer value from SaleControlle idOf5match, to BuyController idText(label). But i'm getting

NullPointerException

I tryed different method which i read in another answers in stuck overflow, but they don't working. Please tell me what i did wrong

Debbuger screen

Sale Controller Class

package sample.controller;

public class SaleController {
    @FXML
    private Button button1;

    private Stage stage;
    public String idOf1match;
    public String idOf2match;
    public String idOf3match;
    public String idOf4match;
    public String idOf5match;

    @FXML
    private void initialize () throws SQLException, ClassNotFoundException {
        initLabels();
    }

    private void initLabels() throws SQLException, ClassNotFoundException {
        ObservableList<Match> matchData = MatchDAO.searchAllMatches();
        idOf1match= String.valueOf(matchData.get(0).getId_match());
        idOf2match= String.valueOf(matchData.get(1).getId_match());
        idOf3match= String.valueOf(matchData.get(2).getId_match());
        idOf4match= String.valueOf(matchData.get(3).getId_match());
        idOf5match= String.valueOf(matchData.get(4).getId_match());
        dataText1.setText(matchData.get(0).getDate());
        dataText2.setText(matchData.get(1).getDate());
        dataText3.setText(matchData.get(2).getDate());
        dataText4.setText(matchData.get(3).getDate());
        dataText5.setText(matchData.get(4).getDate());
        teamText1.setText(matchData.get(0).getTeam());
        teamText2.setText(matchData.get(1).getTeam());
        teamText3.setText(matchData.get(2).getTeam());
        teamText4.setText(matchData.get(3).getTeam());
        teamText5.setText(matchData.get(4).getTeam());
        enemyText1.setText(matchData.get(0).getEnemy());
        enemyText2.setText(matchData.get(1).getEnemy());
        enemyText3.setText(matchData.get(2).getEnemy());
        enemyText4.setText(matchData.get(3).getEnemy());
        enemyText5.setText(matchData.get(4).getEnemy());
    }

    @FXML
    private void buyTicket1() throws IOException {
        BuyController buyController = new BuyController();
        lastFormShow();
    }

    @FXML
    private void buyTicket2() throws IOException {
        BuyController buyController = new BuyController();
        lastFormShow();   
    }

    @FXML
    private void buyTicket3() throws IOException {
        BuyController buyController = new BuyController();
        lastFormShow();
    }

    @FXML
    private void buyTicket4() throws IOException {
        BuyController buyController = new BuyController();
        lastFormShow();
    }

    @FXML
    private void buyTicket5() throws IOException {
        BuyController buyController = new BuyController();
        stage = (Stage) button1.getScene().getWindow();

        buyController.redirectHome(stage, idOf5match);
        buyController.idText.setText(idOf5match);
        // lastFormShow();
    }

    private void lastFormShow() throws IOException {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(getClass().getClassLoader().getResource("sample/UI/BuyTicketLayout.fxml"));

        AnchorPane content = (AnchorPane) loader.load();
        Stage stage = new Stage();
        stage.setTitle("shit");
        stage.setScene(new Scene(content));
        stage.show();
    }
}

BuyController Class

public class BuyController {
    private Parent parent;
    private Scene scene;
    private Stage stage;
    public String enemy;
    public String team;
    public String id;

    @FXML
    private void searchFreePlaces(ActionEvent actionEvent) throws SQLException, ClassNotFoundException {
        try {
            //Get all Event information
            ObservableList<String> areaData =     AreaDAO.searchAllPlaces(idText.getText(),areaText.getSelectionModel().getSelectedItem(),"free");
            //Populate Employees on TableView
            freeplaceCombo.setItems(areaData);
        } catch (SQLException e){
            System.out.println("Error occurred while getting team information from DB.\n" + e);
            throw e;
        }
    }

    @FXML
    private void buyTicket(){

    }

    public BuyController() {
        FXMLLoader fxmlLoader = new     FXMLLoader(getClass().getClassLoader().getResource("sample/UI/BuyTicketLayout.fxml"));
        fxmlLoader.setController(this);
        try {
            parent = (Parent) fxmlLoader.load();
            scene = new Scene(parent, 600, 400);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void redirectHome(Stage stage, String name) {
        stage.setTitle("Home");
        stage.setScene(scene);
        // idText.setText(name);
        stage.hide();
        stage.show();
    }
}
Dipu Raj
  • 1,784
  • 4
  • 29
  • 37
Ilya Kulikov
  • 61
  • 2
  • 12
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Tot Zam Nov 22 '16 at 04:28
  • What I do sometimes is use Properties. When I close one view I set properties. When I open the next view I get those properties. I use this technique when there is a small amount of data I am trying to get from one view to another. – SedJ601 Nov 22 '16 at 19:49

1 Answers1

0

i guess we will need more information about this issue but can you try debugging this line 'idOf5match= String.valueOf(matchData.get(4).getId_match())'. And find out if Dao is returning value or not. If not we have to check the Dao. If you find issue in Dao and cannot fix it then send us its code as well.

Goro
  • 516
  • 4
  • 15