Java fxml app无法正常工作 – 无法找到符号错误

我从https://github.com/HassanAlthaf/AlarmApplication下载了一个java fxml应用程序,当我尝试运行它时,从MainView.java类中获取“找不到符号”错误。 以下是Mainview.java文件中的代码

import java.net.URL; import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.TextField; public class MainView implements Initializable { @FXML private TextField hoursField; @FXML private TextField minutesField; @FXML private TextField secondsField; private final AlarmController alarmController; @FXML private void startAlarm(ActionEvent event) { int response = this.alarmController.startAlarm( this.hoursField.getText(), this.minutesField.getText(), this.secondsField.getText() ); if (response == Alarm.ERROR_INVALID_INPUT) { this.showWarning("Please enter a number only for the times!", "Invalid input received"); } else if (response == Alarm.ERROR_ALARM_ALREADY_ON) { this.showWarning("An alarm is already running at the moment! If you wish to override the current alarm, please stop it first!", "Cannot override current alarm."); } else if (response == Alarm.ERROR_NO_TIME_SET) { this.showWarning("You cannot set an alarm for 0 seconds! Please set a realistic time.", "No time set"); } else { this.showSuccessfulMessage("Successfully scheduled alarm!", "Success"); } } public void showWarning(String message, String title) { Alert alert = new Alert(AlertType.WARNING); alert.setTitle(title); alert.setHeaderText(null); alert.setContentText(message); alert.showAndWait(); } public void showSuccessfulMessage(String message, String title) { Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle(title); alert.setHeaderText(null); alert.setContentText(message); alert.showAndWait(); } @FXML private void stopAlarm(ActionEvent event) { this.alarmController.stopAlarm(); this.showSuccessfulMessage("Successfully stopped the alarm!", "Success"); } public MainView() { this.alarmController = new AlarmController(); } @Override public void initialize(URL url, ResourceBundle rb) { } 

}

您的错误消息应类似于以下内容:

[javac]无法找到符号

[javac] import javafx.scene.control.Alert;

[javac] …………………………………… ^

[javac]符号:类警报

正如评论中所说: Alert类已经在Java 8u40中引入。 有关8u40版本中引入的进一步更改, 请参阅此Oracle博客文章 。

所以:更新你的Java发行版,可以在Oracle页面上下载 ,也可以通过sudo apt-get update && sudo apt-get install openjdk-8-jdk openjfx -y更新它。