0

this is my main class

package system.test.librarysystem;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) throws IOException {
        Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("Login.fxml"));
        primaryStage.setTitle("Library system") ;
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }


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

}

when i try and run it, it gives me these errors

Caused by: java.lang.RuntimeException: Exception in Application start method

Caused by: java.lang.NullPointerException: Location is required.

this use to run fine but for some reason wont run anymore got no clue why, how do i fix this?

  • "Location is required" means the `FXMLLoader` was given a `null` location, which means that `getResource` returned `null` in this case. See the duplicate for details, including techniques for debugging. – Slaw Apr 18 '23 at 15:07
  • Note that `ClassLoader#getResource(String)` always interprets the argument as an absolute resource path. In a modular world, it also requires the resource's package to be opened unconditionally. In your case, it would make more sense and likely make things easier if you just used `Class#getResource(String)` instead. That method interprets arguments that start with `/` as absolute, and those that _do not_ start with `/` as relative to the class's package. – Slaw Apr 18 '23 at 15:10

0 Answers0