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

Nadeem picture Nadeem · May 22, 2015 · Viewed 23k times · Source

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;

Answer

user2922935 picture user2922935 · Aug 25, 2015

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