I don’t know why but every time I try to run my program this error comes out. I am using IntelliJ with Maven with the help of SceneBuilder
for the UI. Java version 20.
I am simply trying to build a desktop app and starting with just the login page from scratch. literally don't have anything other than what I've given here other than password and user verification class.
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at javafx.graphics@20/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics@20/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics@20/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
at javafx.graphics@20/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:1623)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml@20/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2556)
at javafx.fxml@20/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2531)
at com.scanfpdx/com.scanfpdx.ui.LoginPage.start(LoginPage.java:15)
at javafx.graphics@20/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
at javafx.graphics@20/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
at javafx.graphics@20/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at javafx.graphics@20/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
at javafx.graphics@20/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at javafx.graphics@20/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics@20/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)
... 1 more
Exception running application com.scanfpdx.ui.LoginPage
This is my main page. Just using the boilerplate provided by Javafx with IntelliJ with slight modification:
package com.scanfpdx.ui;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import java.io.IOException;
public class LoginPage extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(LoginPage.class.getResource("login-view.fxml"));
AnchorPane root = fxmlLoader.load();
Scene scene = new Scene(root, 400, 300);
stage.setTitle("Login Interface");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
And this is the login controller:
package com.scanfpdx.ui;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
public class LoginController {
@FXML
private TextField usernameField;
@FXML
private PasswordField passwordField;
@FXML
private Button loginButton;
@FXML
private Text statusText;
// @FXML
// protected void onLoginButtonClicked() {
// String username = usernameField.getText();
// String password = passwordField.getText();
//
// if ("username".equals(username) && "password".equals(password)) {
// statusText.setText("Login successful!");
// } else {
// statusText.setText("Login failed. Please check your credentials.");
// }
// }
}
This is the FXML file:
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="253.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.scanfpdx.ui.LoginController">
<Label layoutX="83.0" layoutY="108.0" prefHeight="27.0" prefWidth="85.0" text="User:">
<font>
<Font name="System Bold" size="13.0" />
</font>
</Label>
<Label layoutX="83.0" layoutY="144.0" prefHeight="27.0" prefWidth="85.0" text="Password:">
<font>
<Font name="System Bold" size="13.0" />
</font>
</Label>
<TextField fx:id="usernameField" layoutX="169.0" layoutY="109.0" promptText="Username" />
<PasswordField fx:id="passwordField" layoutX="169.0" layoutY="145.0" promptText="Password" />
<Button layoutX="168.0" layoutY="186.0" mnemonicParsing="false" text="Reset" />
<Button fx:id="loginButton" layoutX="272.0" layoutY="186.0" onAction="#onLoginButtonClicked" snapToPixel="false" text="Login" />
<Box depth="100" height="100" layoutX="126.0" layoutY="35.0" width="100" />
</AnchorPane>