Java fxml app无法正常工作 - 无法找到符号错误 [英] Java fxml app not working - Cannot find symbol error

查看:298
本文介绍了Java fxml app无法正常工作 - 无法找到符号错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i downloaded a java fxml app from https://github.com/HassanAlthaf/AlarmApplication and when i try to run it a get a "cannot find symbol" error from the MainView.java class. Here is the code from the Mainview.java file

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

}    

}

推荐答案

您的错误信息应该类似如下:

Your error message should be similar to the following:


[javac]找不到符号

[javac] cannot find symbol

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

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

[javac] ....................... ................... ^

[javac] ..........................................^

[javac]符号:类警报

[javac] symbol: class Alert

正如评论中所述: Alert 类。
对于8u40版本中引入的进一步更改查看此Oracle博客文章

As it has been said in the comments: The Alert class has been introduced in Java 8u40. For further changes that have been introduced on the 8u40 release see this Oracle blog post.

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

So: Update your Java distribution, either by downloading it on the Oracle page, or by updating it via sudo apt-get update && sudo apt-get install openjdk-8-jdk openjfx -y

这篇关于Java fxml app无法正常工作 - 无法找到符号错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆