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;
fabian
  • 80,457
  • 12
  • 86
  • 114
Nadeem
  • 556
  • 1
  • 4
  • 13
  • 8
    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. – ItachiUchiha May 22 '15 at 10:02
  • 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. – Nadeem May 22 '15 at 10:11
  • 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.] – droida Nov 07 '15 at 05:40

3 Answers3

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
user2922935
  • 439
  • 4
  • 12
  • 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. – Drubio Mar 08 '18 at 09:53
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.

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

Sang9xpro
  • 435
  • 5
  • 8