W
W
WorldDev2022-03-14 11:49:22
Java
WorldDev, 2022-03-14 11:49:22

Compilation error! How to fix?

An error occurred while creating the button click handler. Error while compiling.
Here is my code, everything is written in it, I did it from an online lesson.

package sample;

import javafx.application.Application;
import javafx.event.ActionEvent;
//import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
//import javafx.scene.input.MouseEvent;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Main extends Application {
    public Text question_text;
    public Button answerBtn;

    @Override
    public void start(Stage primaryStage) throws Exception{

        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
//        root.getChildren().addAll(button);
        primaryStage.setTitle("SK exploit");
        primaryStage.setScene(new Scene(root, 747, 460));
        primaryStage.show();

        answerBtn.setOnAction(new ButtonListener());
    }


    public static void main(String[] args) {
        launch(args);
    }

    class ButtonListener implements EventHandler<ActionEvent> {
        @Override
        public void handle(ActionEvent activeEvent) {
            question_text.setText("Text");
        }
    }
}


If that id and elements are registered in sample.fxml via SceneBuilder 8.5.0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2022-03-14
@worldlight

@FXML
public Text question_text;
@FXML
public Button answerBtn;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question