1

I am trying to create my first JavaFX program,using intelliJ IDEA

and i m getting this error :

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 
@0x5ba89dd0) 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 @0x5ba89dd0
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit> 
(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at sample.Main.start(Main.java:13)
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.gtk.GtkApplication._runLoop
(Native Method)
at 
javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.
lambda$runLoop$11(GtkApplication.java:277)
... 1 more
Exception running application sample.Main

This is my FXML file :

`<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
 <?import javafx.scene.layout.AnchorPane?>

 <AnchorPane prefHeight="386.0" prefWidth="621.0" 
 xmlns="http://javafx.com/javafx/8.0.172-ea" 
 xmlns:fx="http://javafx.com/fxml" fx:controller="sample.Controller">
 <children>
  <Label fx:id="m" layoutX="282.0" layoutY="192.0" text="this is a 
  test  " />
</children>
</AnchorPane>`

main.java :

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("Main.fxml"));
    primaryStage.setTitle("Hello World");
    primaryStage.setScene(new Scene(root, 300, 275));
     primaryStage.show();
  }


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

  }}

this is the project structure :

project structure

I even changet the fxml file location but he keep on getting the same error.

the FXML file and Main.java are in the same package

i am Ubuntu

MehdiBal
  • 81
  • 1
  • 9
  • The image is cut exactly where the error message matters. Never post text as image, copy paste the stacktrace here in a code block so it maintains its format. – m0skit0 Mar 12 '19 at 14:35
  • how about now ? – MehdiBal Mar 12 '19 at 15:00
  • Why did you put line breaks in there? Keep the stacktrace as it is, now it is unreadable... If you read the stacktrace you will find that the error is happening in FXMLLoaderHelper.java:38 which code you did not post. – m0skit0 Mar 12 '19 at 15:15
  • Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x5a4c1df1) 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 @0x5a4c1df1 – MehdiBal Mar 12 '19 at 15:16
  • Then post `FXMLLoaderHelper.java`. – m0skit0 Mar 12 '19 at 15:17
  • sorry but what should i do ? (also sorry for my English) – MehdiBal Mar 12 '19 at 15:21
  • see https://stackoverflow.com/questions/53035454/javafx-module-javafx-graphics https://stackoverflow.com/questions/53617191/javafx-controls-could-not-be-found-javafx-11-jdk-11-0-1 https://stackoverflow.com/questions/53694905/javafx-modules-are-not-visible-for-vm – kai Mar 12 '19 at 15:45

1 Answers1

3

i have found the solution , i have added the JavaFX SDK to the modules and modified the module-info.java file because i am using jdk 11

module project-name {
requires javafx.fxml;
requires javafx.controls;

opens sample;
}
MehdiBal
  • 81
  • 1
  • 9