I'm trying to code my first Javafx Application. But I keep getting an error even though my application is ok with the syntax. It's ok because I use the default one when initializing the first JavaFx application in IntelliJ . This here is my code:
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I am using java 8 to run it. But when the application runs then this appears.
/home/jordan/IdeaProjects/new/src/sample/Main.java
Error:(3, 26) java: package javafx.application does not exist
Error:(3, 26) java: package javafx.application does not exist
Error:(7, 20) java: package javafx.stage does not exist
Error:(5, 20) java: package javafx.scene does not exist
And so on... And this also appears
Information:javac 1.8.0_121 was used to compile java sources
I had the same problem which I solved this way:
Go to File->Project Structure and then make sure "Project SDK" is "Java9"; also, "Project Language Level" should be java9. (More precisely it's called "9 Modules, private method in interfaces etc".)
The "project language level" downgrades your Java version. So you think you're using 9 but on the project you're not. This is why you have to change these settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With