-1

Whenever I try compiling my program I keep getting these errors:

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: javafx.fxml.LoadException: /C:/Users/james/Desktop/Spring%20Semester%202020/INFO%202413/CarRental/out/production/CarRental/carRental/address/view/LoginPage.fxml:32

at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2603) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113) at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106) at carRental.address.Main.start(Main.java:24) 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 Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at javafx.fxml/com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:262) at javafx.fxml/com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54) at javafx.fxml/javafx.fxml.FXMLLoader$Element.applyProperty(FXMLLoader.java:520) at javafx.fxml/javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:370) at javafx.fxml/javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:332) at javafx.fxml/javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:242) at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:775) at javafx.fxml/javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2838) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2557) ... 17 more Caused by: 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 com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76) at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273) at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83) at javafx.fxml/com.sun.javafx.fxml.ModuleHelper.invoke(ModuleHelper.java:98) at javafx.fxml/com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:258) ... 25 more Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make javafx.css.ParsedValue javafx.css.CssParser.parseExpr(java.lang.String,java.lang.String) accessible: module javafx.graphics does not "opens javafx.css" to unnamed module @26123535 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:349) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:289) at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:196) at java.base/java.lang.reflect.Method.setAccessible(Method.java:190) at de.jensd.fx.glyphs.GlyphIcon.convert(GlyphIcon.java:248) at de.jensd.fx.glyphs.GlyphIcon.setSize(GlyphIcon.java:144) ... 37 more Exception running application carRental.address.Main

I saw a similar post regarding this issue and I followed what they said would help solve this issue. However, the solution that they provided did not solve my problem. I've also set up my VM to complement my needs for this project. Since I am not using Maven, I set up my VM to this "--module-path C:\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib --add-modules javafx.controls,javafx.fxml".

My code:

package carRental.address;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.fxml.FXMLLoader;
import javafx.scene.input.MouseEvent;
import javafx.stage.StageStyle;

public class Main extends Application {

    private double xOffSet = 0;
    private double yOffSet = 0;

    public static void main(String[] args) {

        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("view/LoginPage.fxml"));

        Scene scene = new Scene(root);

        primaryStage.initStyle(StageStyle.UNDECORATED);

        root.setOnMousePressed(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                xOffSet = mouseEvent.getSceneX();
                yOffSet = mouseEvent.getSceneY();
            }
        });

        root.setOnMouseDragged(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                primaryStage.setX(mouseEvent.getSceneX() - xOffSet);
                primaryStage.setY(mouseEvent.getSceneY() - yOffSet);
            }
        });
        
    }
}

My FXML file: FXML file

The controller: Controller file

Now, I am not too sure how to fix this issue as I am new to JavaFX. If someone could point out where my mistake is that would be great!

notjames
  • 81
  • 5
  • 1
    Welcome to Stack Overflow! Please be sure to take the [tour] and read the [ask] FAQ before posting a question. To get help with errors you're receiving, please do not just dump your code and ask us to assume the issue. You should [edit] your question and post the exact error message and what line of your code is causing it. It is also almost always in **your** best interest to read how to include a [mcve] with debugging questions. – Zephyr Mar 17 '21 at 04:15
  • [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) – Abra Mar 17 '21 at 19:49

1 Answers1

1

This is the relevant part of the stack trace.

java.lang.NullPointerException: Location is required. at
carRental.address.Main.start(Main.java:24)

I'm guessing that the following line is line 24 in file Main.java

Parent root = FXMLLoader.load(getClass().getResource("src/carRental/address/view/LoginPage.fxml"));

The path is wrong. It has to be relative to the location of the compiled java class, i.e. file Main.class (and not Main.java).

Your IDE copies the FXML from the src folder to the output folder (which I'm guessing is named bin).

Try changing the above line of [java] code to the following:

Parent root = FXMLLoader.load(getClass().getResource("view/LoginPage.fxml"));

EDIT

You have edited your question and implemented my suggested changes and that has solved your initial problem.

Your new problem is that your LoginPage.fxml file indicates a JavaFX version, namely 15.0.1

Note that this is not required. You can safely omit that part. In other words remove the following:

xmlns="http://javafx.com/javafx/15.0.1"
Abra
  • 19,142
  • 7
  • 29
  • 41
  • I changed it to that and I received a new error: "Mar. 17, 2021 12:52:30 P.M. javafx.fxml.FXMLLoader$ValueElement processValue WARNING: Loading FXML document with JavaFX API of version 15.0.1 by JavaFX runtime of version 11.0.2" – notjames Mar 17 '21 at 19:55
  • @notjames remove the following from your `LoginPage.fxml` file: `xmlns="http://javafx.com/javafx/15.0.1"` It is **not** required. – Abra Mar 17 '21 at 19:58
  • I followed your instruction and got rid of xmlns="http://javafx.com/javafx/15.0.1". It got rid of the "Mar. 17, 2021 12:52:30 P.M. javafx.fxml.FXMLLoader$ValueElement processValue WARNING: Loading FXML document with JavaFX API of version 15.0.1 by JavaFX runtime of version 11.0.2" error. But it is essentially the same. – notjames Mar 17 '21 at 20:10