0

I've reinstall my OS from Win7 to 10. After reinstalling Intellij IDEA + Corretto_11 + JavaFX libary I cannot compile programa that was working.

I'm quite green in Java, so i don't know hot to approche the problem.

Project set to Correto_11, language level 11, and FX libary added to module.

Even code from Course does not compile.

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x3a0bd002) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x3a0bd002
    at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
    at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
    at main.Main.start(Main.java:18)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Exception running application main.Main

Process finished with exit code 1

Edit:

After adding module I have following error:

"C:\Program Files\Amazon Corretto\jdk11.0.7_10\bin\java.exe" --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.1\lib\idea_rt.jar=50795:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.1\bin" -Dfile.encoding=UTF-8 -p C:\Users\Sebastian\Documents\javafx_11\lib\javafx.base.jar;C:\Users\Sebastian\Documents\javafx_11\lib\javafx.graphics.jar;C:\Users\Sebastian\Desktop\JavaProjects\JavaFX_ToDo\out\production\JavaFX_ToDo;C:\Users\Sebastian\Documents\javafx_11\lib\javafx-swt.jar;C:\Users\Sebastian\Documents\javafx_11\lib\javafx.controls.jar;C:\Users\Sebastian\Documents\javafx_11\lib\javafx.fxml.jar;C:\Users\Sebastian\Documents\javafx_11\lib\javafx.media.jar;C:\Users\Sebastian\Documents\javafx_11\lib\javafx.swing.jar;C:\Users\Sebastian\Documents\javafx_11\lib\javafx.web.jar -m JavaFX.ToDo/main.Main
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\Sebastian\Desktop\JavaProjects\JavaFX_ToDo\out\production\JavaFX_ToDo
Caused by: java.lang.module.InvalidModuleDescriptorException: Package JavaFX.ToDo not found in module

Process finished with exit code 1

Edit 2:

Project structure: enter image description here

Edit 3: Adding how my module look like:

module JavaFX.ToDo {
    requires javafx.graphics;
    requires javafx.controls;
    requires javafx.fxml;

    opens JavaFX.ToDo;
}

Edit 4:

Adding main content:

package main;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import main.models.TaskData;

import java.io.IOException;



public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("mainwindow.fxml"));
        primaryStage.setTitle("JavaFX: ToDo-App");
        primaryStage.setScene(new Scene(root, 900, 500));
        primaryStage.show();
    }




    public static void main(String[] args) {
        launch(args);

    }
    @Override
    public void stop() throws Exception {
        try {
            TaskData.getInstance().storeTasks();

        } catch (IOException e){
            System.out.println(e.getMessage());
        }
    }

    @Override
    public void init() throws Exception {
        try {
            TaskData.getInstance().loadTasks();

        } catch (IOException e){
            System.out.println(e.getMessage());
        }
    }

}

Or i can push all on my github.

https://github.com/s-osyra/JavaFX_ToDoList

Sebastian
  • 5
  • 4
  • If you have a module-info file, declare your module `open`. Maybe it's a reflection thing – user May 09 '20 at 18:29
  • If you don't have a module-info file, I would suggest making one. Also, you should give `--add-modules ALL-MODULE-PATH` (or just the modules you need, like javafx.fxml) as one of the jvm's options – user May 09 '20 at 18:39
  • This is the important part, I think: `javafx.graphics does not export com.sun.javafx.util to unnamed module @0x3a0bd002` (that unnamed module is yours). You could maybe fix that with `--add-exports` too, but that's probably not a good idea because it's hacky. – user May 09 '20 at 18:45
  • I've added, and there is following error: Error occurred during initialization of boot layer – Sebastian May 09 '20 at 18:50
  • Your project structure would be helpful – user May 09 '20 at 18:54
  • You will need to post the contents of your `Main.java` – smac89 May 09 '20 at 18:57
  • Its all in now. I'm trying to work with it but still im confused. Its more likly problem with configuration or depencities than with code. – Sebastian May 09 '20 at 19:38
  • You should probably name your module something like javafx_todo instead of JavaFx.ToDo. It's not the convention. – user May 09 '20 at 20:43
  • Also, `opens` is used for packages. `JavaFx.ToDo` is not a package, it's your module name – user May 09 '20 at 20:44
  • See this answer: https://stackoverflow.com/questions/46482364/what-is-an-open-module-in-java-9-and-how-to-use-it – user May 09 '20 at 20:46

2 Answers2

0

The first error happened because your module wasn't open, and the javafx.fxml module (specifically FXMLLoader) wanted to use reflection.

The second error's just because you're using opens incorectly. It's meant to open packages, not modules.

This is your module-info file now:

module JavaFX.ToDo {
    requires javafx.graphics;
    requires javafx.controls;
    requires javafx.fxml;

    opens JavaFX.ToDo; //Here's the error
}

This is incorrect, because you don't have a package called JavaFX.ToDo, it's your module name. To make your module open (so javafx.fxml can do reflective access operations), you need to declare your module open like this:

open module JavaFX.ToDo {
  ...
}

xor this:

module JavaFX.ToDo {
  ...
  opens main; //This is where Main.java is, and where you use FXMLLoader
}


If you want it to be more secure, you could also declare it like this:

module JavaFX.ToDo {
  requires javafx.fxml;
  opens main to javafx.fxml; //Only fxml has reflective access to your package now
}

I would suggest reading this article about Java 9's module system. Scroll down to where they talk about open modules.

Side note: Module names are lowercase by convention. You probably want something like javafx_todo

user
  • 7,435
  • 3
  • 14
  • 44
0

I solved this as follows in IntelliJ: Run -> Edit configuration -> Configuration tab -> add following in VM options: --module-path c:\javafx-sdk-14.0.1\lib --add-modules=javafx.controls,javafx.fxml

johanpm
  • 13
  • 2