Java非法启动类型)预期

-6 java syntax javafx compiler-errors menu

package tic.tac.toe.menu;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class TicTacToeMenu extends Application {

@Override
public void start(Stage primaryStage) {
    Button start = new Button();
    start.setText("How to Play?");
    start.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            System.out.println("\n"+"The goal of tic-tac-toe is to get 3 of your pieces in a row vertically, horizontally, or diagonally ");
            System.out.println("To play this game click inside a square to put down your piece, you choose to be 'x' or 'o' at the start");
        }
    });

    StackPane root = new StackPane();
    root.getChildren().add(start);

    Scene scene = new Scene(root, 350, 250);

    primaryStage.setTitle("Tic-Tac-Toe");
    primaryStage.setScene(scene);
    primaryStage.show();}

public void exit(Stage primaryStage) {
    Button exit = new Button();
    exit.setText("Quit?");
    exit.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.exit(0);
        })} // this line I get the error

    StackPane root=new StackPane();
    root.getChildren().add(exit);
    Scene scene = new Scene(root, 350, 250);
    primaryStage.setScene(scene);
    primaryStage.show();
}
}
Run Code Online (Sandbox Code Playgroud)

我是Java的新手,我正在尝试制作一个菜单,但是在第40行我得到一个错误,说明非法启动类型,我很困惑这意味着什么.我认为我的语法错误但不确定要修复什么.

dka*_*zel 5

从中更改代码

})} // this line I get the error
Run Code Online (Sandbox Code Playgroud)

对此

}}); 
Run Code Online (Sandbox Code Playgroud)

你需要连续2次关闭括号:第一个完成handle方法,第二个完成EventHandler

外部的近括号是完成 setOnAction通话.最后用一个半冒号来完成声明.


Ell*_*sch 5

exit.setOnAction如下更改您的电话

exit.setOnAction(new EventHandler<ActionEvent>() {
    public void handle(ActionEvent event) {
        System.exit(0);
    }
}); // NOT })}
Run Code Online (Sandbox Code Playgroud)


Sib*_*bbo 5

替换})}}});.您必须按照打开它们的相反顺序关闭块.