V
V
Vladyslav GmGameFilm2020-01-09 18:42:22
Java
Vladyslav GmGameFilm, 2020-01-09 18:42:22

Why doesn't the JavaFX application start?

Main class:

package org.openjfx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class MainApp extends Application {
  @Override
  public void start(Stage stage) throws Exception {
    stage.setScene(new Scene(new FlowPane(), 640, 480));
    stage.setTitle("Example title");
    stage.show();
  }
  public static void main(String[] args) {
    launch(args);
  }
}

In the module:
module hellofx {
  requires javafx.graphics;
}

On startup it gives an error:
Exception in Application constructor
Exception in thread "main" 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 java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class org.openjfx.MainApp
  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:890)
  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.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class org.openjfx.MainApp (in module hellofx) because module hellofx does not export org.openjfx to module javafx.graphics
  at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
  at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
  at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
  at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:802)
  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

I found in Google that the problem is in the public modifier, but I have all the methods and classes open, so where did java come from. lang. I can't understand IllegalAccessException. Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladyslav GmGameFilm, 2020-01-09
@GmGameFilm

Stubbornly did not notice the continuation of this line xD. I'll leave it, maybe it will be useful to someone.
The module should have:

module hellofx {
  requires javafx.graphics;
  exports org.openjfx to javafx.graphics;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question