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

时间:2017-05-15 15:03:41

标签: java javafx netbeans javafx-8 alert

我从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) {

}    

}

1 个答案:

答案 0 :(得分:0)

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

  

[javac]无法找到符号

     

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

     

[javac] .......................................... ^ < / p>      

[javac] symbol:class Alert

正如评论中所述:Java {8}中已经引入了Alert类。 有关在8u40版本see this Oracle blog post上引入的进一步更改。

所以:更新您的Java发行版,by downloading it on the Oracle page或通过sudo apt-get update && sudo apt-get install openjdk-8-jdk openjfx -y更新它