Я пытаюсь создать оконную программу, используя JavaFx и SceneBuilder. По какой-то причине я не могу получить текст, который я sh должен отображать в последнем окне после нажатия кнопки. Окно открывается, но текст никогда не отображается и не применяется к моим ярлыкам. Я получаю исключение Nullpointer для моего метода displayTime, я не понимаю, почему. Вот код для моего класса контроллера, а также файл F XML для моего последнего окна.
package plan;
import java.io.IOException;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
public class MainController{
@FXML
public String act1, act2, act3, act4;
@FXML
public Button input;
@FXML
public Button proceed;
@FXML
public Button start;
@FXML
public Button calcTime;
@FXML
public TextField task1;
@FXML
public TextField task2;
@FXML
public TextField task3;
@FXML
public TextField task4;
@FXML
public TextField hours;
@FXML
public Label fplan1;
@FXML
public Label fplan2;
@FXML
public Label fplan3;
@FXML
public Label fplan4;
@FXML
public Label timesCalc;
@FXML
private void startPlan(ActionEvent event) throws IOException{
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("NewPlan.fxml"));
Scene scene = new Scene(root); //creation of a scene
primaryStage.setScene(scene);
primaryStage.setTitle("YOUR DAILY PLAN");
primaryStage.show();// Displays window/ stage
Stage currentStage = (Stage)start.getScene().getWindow();
currentStage.close();
}
@FXML
private void inputDay(ActionEvent event)throws IOException {
Stage currentStage = (Stage)input.getScene().getWindow();
currentStage.close();
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("NormalDay.fxml"));
Scene scene = new Scene(root); //creation of a scene
primaryStage.setScene(scene);
primaryStage.setTitle("YOUR DAILY PLAN");
primaryStage.show();// Displays window/ stage
}
@FXML
private void calcTime(ActionEvent event)throws IOException {
Day day = new Day(Integer.parseInt(hours.getText()));
act1 = "Time you have for " + task1.getText() + " is " + Integer.toString(day.getT(1)) + " hours " + Integer.toString(day.getT(11));
act2 = "Time you have for " + task2.getText() + " is " + Integer.toString(day.getT(2)) + " hours " + Integer.toString(day.getT(22));
act3 = "Time you have for " + task3.getText() + " is " + Integer.toString(day.getT(3)) + " hours " + Integer.toString(day.getT(33));
act4 = "Time you have for " + task4.getText() + " is " + Integer.toString(day.getT(4)) + " hours " + Integer.toString(day.getT(44));
timesCalc.setText("Time Calculation Completed!");
//TIMES CALCULATED MESSAGE
}
@FXML
private void displayTime(ActionEvent event)throws IOException {
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("FinalDay.fxml"));
Scene scene = new Scene(root); //creation of a scene
primaryStage.setScene(scene);
primaryStage.setTitle("YOUR DAILY PLAN");
primaryStage.show();// Displays window/ stage
fplan1.setText("TEST");
fplan2.setText(act2);
fplan3.setText(act3);
fplan4.setText(act3);
//ANOTHER display method??? times still wont show on final page after continue button
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="500.0" prefWidth="700.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171" fx:controller="plan.MainController">
<children>
<HBox alignment="CENTER" layoutY="14.0" prefHeight="100.0" prefWidth="704.0">
<children>
<Label text="YOUR PLAN" textFill="#3751e8">
<font>
<Font name="System Italic" size="36.0" />
</font>
</Label>
</children>
</HBox>
<VBox layoutX="11.0" layoutY="121.0" prefHeight="378.0" prefWidth="683.0" spacing="50.0">
<children>
<Label fx:id="fplan1" prefHeight="35.0" prefWidth="762.0">
<font>
<Font size="24.0" />
</font>
</Label>
<Label fx:id="fplan2" prefHeight="35.0" prefWidth="700.0">
<font>
<Font size="24.0" />
</font>
</Label>
<Label fx:id="fplan3" prefHeight="35.0" prefWidth="957.0">
<font>
<Font size="24.0" />
</font>
</Label>
<Label fx:id="fplan4" prefHeight="35.0" prefWidth="734.0">
<font>
<Font size="24.0" />
</font>
</Label>
</children>
</VBox>
</children>
</AnchorPane>