1

I've started learning JavaFX for a personal project and things were going well until I hit an issue with creating a set of text fields. As far as I can tell, the code is correct and the IDE I'm using doesn't give any indication of an error. But when I attempt to run the program, it spits out a long list off errors that don't occur when I comment out the code creating the textfields. The program runs exactly as it should when those lines of code are left out.

I'm using InteliJ Idea, Windows 10, Javafx SDK 14.0.1, and Java JDK 14.0.1

I've included the code I'm using below. The program is extremely straight forward so I included all of it just in case I've overlooked something earlier on.

package library.test;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.shape.*;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class main extends Application {

@Override
public void start(Stage primaryStage) {

    // Create the grid plane
    GridPane pane =new GridPane();
    pane.setHgap(10);
    pane.setVgap(6);
    pane.setAlignment(Pos.TOP_CENTER);

    // Create the scene
    Scene scene=new Scene(pane,500,500);
    primaryStage.setScene(scene);
    primaryStage.setTitle("Book Catalog");
    primaryStage.show();

    // Create the elements for the table
    Text tTitle = new Text("Title");
    Text tAuthor = new Text("Author");
    Text tGenre = new Text("Genre");
    Text tFormat = new Text("Format");
    Text tISBN = new Text("ISBN");

    TextField fTitle=new TextField();
    TextField fAuthor=new TextField();
    TextField fGenre=new TextField();
    TextField fFormat=new TextField();
    TextField fISBN =new TextField();

    // Add the elements of the scene
    pane.add(tTitle,1,1);
    pane.add(tAuthor,3,1);
    pane.add(tGenre,5,1);
    pane.add(tFormat,7,1);
    pane.add(tISBN,8,1);

    pane.add(fTitle,2,3);

}

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

I'm extremely new to this side of programming so I apologize if I missed something obvious. Thanks in advance!

ADDITION

Included the stack trace

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:564)
    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:564)
    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:832)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x25c44106) 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 @0x25c44106
    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(AccessController.java:391)
    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 sample.Main
TeaDrinker
  • 199
  • 1
  • 11
  • 1
    nothing obvoiusly wrong asaics - please add the complete stacktrace .. and stick to java naming conventions – kleopatra Jul 03 '20 at 04:08
  • btw, the title does not match your description (_compile error_ vs _when trying to run_) – kleopatra Jul 03 '20 at 04:12
  • 4
    Please post the _entire stack trace_ as suggested by @kleopatra. That said, since `TextField` is the only class you're trying to load from the `javafx.controls` module I'm going to guess you're getting an `IllegalAccessError`, in which case this question is a duplicate of [JavaFX 11: IllegalAccessError when creating Label](https://stackoverflow.com/questions/54291958/javafx-11-illegalaccesserror-when-creating-label). – Slaw Jul 03 '20 at 06:38
  • @kleopatra I've added the stack trace. I'm really not sure why I didn't think to include it in the first place. I also want to add that the code causes compile errors when I try to add buttons. I'm starting to think the text fields are the only thing that actually work. – TeaDrinker Jul 03 '20 at 19:44
  • @Slaw I looked through the stack trace (added it for viewing) and I'm not seeing any reference to an ilegal access error. I'm reading through the article you linked right now though. The similarities are striking. – TeaDrinker Jul 03 '20 at 19:48
  • I was wrong about the specifics but you _are_ getting an `IllegalAccessError`. The problem is with the `javafx.fxml` module instead of the `javafx.controls` module. The solution, however, is extremely similar to the one in the linked question—add `javafx.fxml` to your `--add-modules` argument. That said, I don't see how the code you posted could be throwing the error it is; there's no reference to anything related to FXML. Are you sure the example you provided is the same code throwing the provided error? – Slaw Jul 03 '20 at 19:59
  • "_I'm not seeing any reference to an ilegal [sic] access error_" – Note that the `IllegalAccessError` is the last `Caused by` in the stack trace, which means it's the root error. If you're not sure how to read a stack trace then check out [What is a stack trace, and how can I use it to debug my application errors?](https://stackoverflow.com/questions/3988788/). – Slaw Jul 03 '20 at 20:06
  • I read through the article you linked and it turned out my issue was the VM options parameter on my configuration. I set it to the appropriate parameters and my code runs exactly as it should now. Thanks for the help! – TeaDrinker Jul 03 '20 at 20:06

1 Answers1

0

Thanks to the help of @Slaw, I was able to solve this issue. In the article JavaFX 11: IllegalAccessError when creating Label it was shown that this is simply a VM option issue. Once I put in the appropriate path options and parameters shown in the aforementioned link, my code worked exactly as intended.

Thanks again so much to @Slaw for the help! Sorry this took so long to return to and answer. I honestly thought I already had done this.

TeaDrinker
  • 199
  • 1
  • 11