导入 javafx.scene.control.Alert 无法解析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30393751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 09:32:39  来源:igfitidea点击:

The import javafx.scene.control.Alert cannot be resolved

javaeclipsejavafxefxclipse

提问by Nadeem

I am getting the error with following two imports in Eclipse:

我在 Eclipse 中出现以下两个导入错误:

import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;

The errors are: "The import javafx.scene.control.Alert cannot be resolved" and same is true for the 2nd import statement.

错误是:“无法解析导入 javafx.scene.control.Alert”,第二个导入语句也是如此。

I am using Eclipse Version: Luna Service Release 2 (4.4.2) and have installed e(fx)clipse with latest JDK 1.8 (1.8.0_45).

我正在使用 Eclipse 版本:Luna Service Release 2 (4.4.2) 并安装了 e(fx)clipse 和最新的 JDK 1.8 (1.8.0_45)。

There is no problem with other javafx related import statements, such as

其他javafx相关的import语句没有问题,比如

import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;

回答by user2922935

I had the same problem, until I installed the JDK 1.8.0_60. That's right, installing the latest JDK helped! enter image description here

我遇到了同样的问题,直到我安装了 JDK 1.8.0_60。没错,安装最新的 JDK 有帮助! 在此处输入图片说明

After you install the latest JDK, change the settings on the Eclipse There are two steps to the process:

安装最新的 JDK 后,更改 Eclipse 上的设置的过程有两个步骤:

  1. Select the appropriate JRE in Eclipse > Preferences > Java > Installed JREsas shown here: enter image description here

    1. In Project > Properties > Java Build Path, Add Library as depicted below: enter image description here
  1. 选择适当的 JRE,Eclipse > Preferences > Java > Installed JREs如下所示: 在此处输入图片说明

    1. Project > Properties > Java Build Path,添加库如下图: 在此处输入图片说明

回答by Central Thinking Unit

I got the same problem on Eclipse (MacOSX Yosemite) this morning but yesterday everything worked... To solve the problem I just deselected the checkbox for another JDK in Project > Properties > Java Build Pathrestarted Eclipse, reselected the good one (JDK 1.8.0_60), restarted Eclipse again and voilà ! Just a weird bug with checkboxes...

今天早上我在 Eclipse (MacOSX Yosemite) 上遇到了同样的问题,但昨天一切正常......为了解决这个问题,我只是在Project > Properties > Java Build Path重新启动的 Eclipse 中取消选中另一个 JDK 的复选框,重新选择好的(JDK 1.8.0_60),再次重新启动 Eclipse瞧!只是一个带有复选框的奇怪错误......

Hope it ll help you.

希望它会帮助你。

回答by Sang9xpro

You need to change the java version. Java 1.8.0_45 do not include javafx.scene.control.Alert You can download version 1.8.0_221 here

您需要更改java版本。Java 1.8.0_45 不包含 javafx.scene.control.Alert 您可以在此处下载 1.8.0_221 版本