Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javafx packegs do not Exist IntelliJ

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
like image 854
Luis Carlos Froes Avatar asked Mar 10 '23 06:03

Luis Carlos Froes


1 Answers

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.

like image 178
Turan Khan Avatar answered Mar 15 '23 07:03

Turan Khan