小编Dar*_*its的帖子

Java:不能引用非最终变量

我写了一些代码,一切正常,但是当我在另一台计算机上打开相同的代码时,出现以下错误:

Cannot refer to the non-final local variable usernameTextField defined in an enclosing scope
Cannot refer to the non-final local variable portTextField defined in an enclosing scope
Cannot refer to the non-final local variable usernameTextField defined in an enclosing scope
Cannot refer to the non-final local variable portTextField defined in an enclosing scope
Run Code Online (Sandbox Code Playgroud)

给出此错误的代码:

private static GridPane initGUI(){
    GridPane root = new GridPane();
    TextField usernameTextField = new TextField();
    TextField portTextField = new TextField();
    Button button = new Button("Login!");
    root.add(new Label("Username:"),0,0); …
Run Code Online (Sandbox Code Playgroud)

java javafx

0
推荐指数
1
解决办法
8784
查看次数

标签 统计

java ×1

javafx ×1