Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some javafx classes cannot be resolved in Eclipse using Java SE 8u25

I installed the Java SE 8u25 JDK (64 Bit) from Oracle, which should include JavaFX.

I'm using Win7 64 Bit, Eclipse Helios and included the jre in the classpath as shown here: enter image description here

I'm trying to replicate the code from this tutorial: http://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm

Eclipse shows me "The type javafx.scene.control.Control cannot be resolved. It is indirectly referenced from required .class files" when trying to use javafx.scene.control.Button.setText(String). A similar problem occurs when trying to create a StackPane object.

Here's the code so far:

package javaFX;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class HelloWorld extends Application {

@Override
public void start(Stage primaryStage) throws Exception {

    Button btn = new Button();
    btn.setText("Hello world!");
    btn.setOnAction(new EventHandler<ActionEvent>(){

        @Override
        public void handle(ActionEvent arg0) {
            System.out.println("Hello world!");
        }

    });

    StackPane root = new StackPane();

}
}

Tl;dr: Some JavaFX classes seem to be missing in Java SE 8u25 or I made a mistake in including the jre in the build path.

like image 252
GeckStar Avatar asked Jan 18 '15 16:01

GeckStar


People also ask

How do I fix JavaFX error?

If this is your case also, you can do fix this by simply right-clicking on the javaFX project folder-> Build Path-> Configure Build Path-> Select JavaFX SDK-> Remove library-> Select classpath -> add library-> user library-> select library-> apply. Save this answer.

Does JDK 15 support JavaFX?

JavaFX is not part of the jdk since java 11.

Does JDK 17 support JavaFX?

JavaFX is not included in the JDK since Java 9 (with the exception of the Azul JDK, IIRC).

Does JavaFX run on JDK 11?

For JDK 11 and later releases, Oracle has open sourced JavaFX. You can find more information at OpenJFX project.


1 Answers

NOTE: I've seen that you are using Eclipse Helios. You could also download a latest version of Eclipse Luna. This will work also.


You could try e(fx)clipse which might be a useful IDE extension when developing FX apps with Eclipse. To do so follow these steps:

  1. Open Eclipse and go to Help > Install New Software and insert the URL http://download.eclipse.org/efxclipse/updates-released/1.1.0/site/ under "Work with:" and press enter
  2. Once the packages are loaded, select and install them both
  3. After a restart of Eclipse you can go to File > New > Other ... and select JavaFX > JavaFX Project
  4. There is one more step to do: add the jfxrt.jar to the classpath by going to the project properties and selecting "Add external JAR ..."
    • Windows: C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext
    • Mac OS: ./Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/jfxrt.jar.
  5. Ready to make cute JavaFX GUIs!

Working example.

Notice: e(fx)clipse provides much more support for developing JavaFX applications. Feel free to take a look.

like image 59
mythbu Avatar answered Oct 19 '22 22:10

mythbu