The import javafx.scene.control.Alert cannot be resolved
Asked Answered
U

3

17

I am getting the error with following two imports in 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.

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

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

import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;
Uroscopy answered 22/5, 2015 at 9:59 Comment(3)
Can you make sure that eclipse is using the installed JDK i.e. 1.8.0_45? Alerts were introduced in Java 8u40, so if eclipse is using any level lower than this, it will throw compilation errors.Psychotechnics
Thanks a lot ItachiUchiha :) I installed the latest JDK 1.8 update 45 but eclipse was still using the JRE 1.8.0_20. I have changed this now and problem has been fixed. Thanks.Uroscopy
Yes,thx for remind me update the JDK to 1.8.0.45+. My steps below: 1. install the right JDK (1.8.0_45 +),mine 1.8.0_60. 2.update my path variable to new JAVA_HOME && JDK's \jre\bin directory. 3.open eclipse(version 4.4+ support java8 )->window->preferences-> java->Installed JREs,click the edit btn in the right panel to update the directory to new jdk's bin ,mine is D:\Program Files\Java\jdk1.8.0_65,then all fixed :) [ps. The last step fixed Nadeem's problem about eclispe still use the old JRE.]Hardwood
L
23

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

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

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

    1. In Project > Properties > Java Build Path, Add Library as depicted below: enter image description here
Logic answered 25/8, 2015 at 7:14 Comment(1)
This answer worked to me, should be marked as accepted. Or if it didn't work to the guy who made question he should explain something more.Diplostemonous
L
4

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 Path restarted Eclipse, reselected the good one (JDK 1.8.0_60), restarted Eclipse again and voilà ! Just a weird bug with checkboxes...

Hope it ll help you.

Linesman answered 10/9, 2015 at 9:37 Comment(0)
B
0

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

Benildis answered 7/10, 2019 at 4:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.