java - 将 JavaFX TextArea 的输入打印到控制台会出现错误
问题描述
我正在尝试将 TextArea 中用户的输入打印到控制台。
//controller
private void btnClick(ActionEvent event) {
System.out.println(input.getText());
}
//fxml
...
<left>
<Button id="booton" fx:id="booton" mnemonicParsing="false" onAction="#btnClick" text="Button" BorderPane.alignment="CENTER" />
</left>
<right>
<TextArea id="input" prefHeight="200.0" prefWidth="200.0" promptText="give me input" BorderPane.alignment="CENTER" />
</right>
</BorderPane>
它在运行更多时给了我这个错误:
Caused by: java.lang.NullPointerException: Cannot invoke "javafx.scene.control.TextArea.getText()" because "this.input" is null at sample.Controller.btnClick(Controller.java:31)
解决方案
推荐阅读
- regex - Regex - Delete everything before first match
- java - 分布式系统中如何分配任务?
- html - 如何使 Bootstrap Modal 中的输入字段成为必填项?
- java - Java Itext pdf - java.io.IOException ...未作为文件或资源找到
- java - 来自参数变量的 CSV 标头
- django - 使用 GET 请求验证和登录用户
- hive - 使用 Hive-JDBC 在 Hive 中批量插入
- distributed-database - 如何确定正确的 TiDB 和 TiDB-Ansible 版本?
- ios - Xamarin Live Player iOS TestFlight
- python - 当 Pyspark UDF 的 return 语句中的 func 调用没有返回输出