5

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.

Jon Heller
  • 34,999
  • 6
  • 74
  • 132
GeckStar
  • 1,136
  • 1
  • 14
  • 22
  • Why have you got Java 6 and Java 8 in the build path? This is probably causing confusion. – greg-449 Jan 18 '15 at 16:09
  • I removed it. I only have the `jre1.8.0_25`, `JUnit 4` and `jfxrt.jar` in the build path. I cleaned and refreshed the project and the problem is still there. – GeckStar Jan 18 '15 at 16:39

3 Answers3

16

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.

mythbu
  • 786
  • 1
  • 7
  • 20
  • 1
    Yes, I wasn't able to install e(fx)clipse on **Helios**, it might be too old. I installed **Luna** and it worked after including `jfxrt.jar` to the class path. I suspect the problem to be that I couldn't switch to a newer Java compiler other than 1.6 in Helios. – GeckStar Jan 19 '15 at 10:53
  • Where is this in Linux? – Nikola Stojaković Dec 12 '15 at 19:21
  • There exists no `jre/` in `/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/`, how can i fix this? I tried reinstalling, but that didnt work. – Arjun May 18 '19 at 17:28
1

EDIT :

You haven't import the class for StackPane :

import javafx.scene.layout.StackPane;

Previous answer :

Basically you haven't import your javafx library , you can Add External JARs , and pointing out to jfxrt.jar, and it will work just fine.

In my path , jfxrt.jar is in :

C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext

There is a simple way,

Fevly Pallar
  • 3,059
  • 2
  • 15
  • 19
  • 1
    Shouldn't it be included in the jdk? Either way, I added it as an external JAR to the build path of the project, but that didn't solve the problem. – GeckStar Jan 18 '15 at 16:34
  • it's jre inside jdk , take a look at my path above..:) ,jdk also has jre folder if you see correctly – Fevly Pallar Jan 18 '15 at 16:37
  • I meant javaFX should be included in the jre, i.e. I shouldn't need to add the `jfrxt.jar` in order to use it afaik. However, [I included it](http://i.imgur.com/UZ8j5Y6.png) as you told me to, but the problem's still there. – GeckStar Jan 18 '15 at 16:44
  • Thanks for your help. If I try to import StackPane as you wrote it, I get `The import javafx.scene.layout.StackPane cannot be resolved`. I restarted Eclipse, but it's still the same. I got it to work in **Netbeans IDE 8.0** though by adding `jfxrt.jar`. It's just a workaround, but I'm fine with it atm. – GeckStar Jan 18 '15 at 17:21
  • The import javafx.scene.layout.StackPane, don't forget to put ";" after the declaration – Fevly Pallar Jan 18 '15 at 17:28
0

Installing the latest JDK will help. Please see the two links: enter link description here enter link description here

Community
  • 1
  • 1
user2922935
  • 439
  • 4
  • 12