【发布时间】:2015-12-20 02:07:51
【问题描述】:
我在另一个文件中执行了这个类,java 告诉我
"Unexpected return value",
我已经搜索和搜索,但看不到我做错了什么。我是一个巨大的 Java 菜鸟,所以任何帮助将不胜感激。
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.geometry.*;
public class PopUpBox {
public static void display(String title, String message) {
Stage window = new Stage();
TextField textField = new TextField();
//Block events to other windows
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
window.setMinWidth(250);
//Make a label that closes the window
Label label = new Label();
label.setText(message);
Button closeButton = new Button("Done");
closeButton.setOnAction(e -> {
Integer test = Integer.parseInt(textField.getText());
//return test;
System.out.println(test.getClass());
window.close();
}
);
VBox layout = new VBox(10);
layout.getChildren().addAll(textField, closeButton);
layout.setAlignment(Pos.CENTER);
//Display window and wait for it to be closed before returning
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();
}
}
【问题讨论】:
-
ActionHandler#handle是一个 void 方法,你不能从这个方法返回一个值(这是我不喜欢 lambda 表达式的原因之一,它们对没有经验的开发人员隐藏了这些重要的细节) -
从哪里获得“意外的返回值”。如果您遇到异常,请分享堆栈跟踪或分享您拥有的任何日志。