I get a long error message when I run the program. I am using Netbeans IDE 8.2. At first I thought it is just about wrong FXML src. Because it happened yesterday and the error was the same and i solved it changing fx:controller="schoolmanagementsystem.LoginController" source. But today i got the same error and couldn't solve. Thanks for your helps in advance.
The error is:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:873)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at schoolmanagementsystem.SchoolManagementSystem.start(SchoolManagementSystem.java:24)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:187)
... 1 more
Exception running application schoolmanagementsystem.SchoolManagementSystem
This is main page
package schoolmanagementsystem;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class SchoolManagementSystem extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Login.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("Login.css").toExternalForm());
stage.setScene(scene);
stage.setTitle("Login | School Management System");
stage.setResizable(false);
Image icon = new Image("sms.png");
stage.getIcons().add(icon);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
This is its controller page
package schoolmanagementsystem;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
public class LoginController implements Initializable{
switchBetweenPages switchpage= new switchBetweenPages();
Alerts alert= new Alerts();
@FXML
private TextField txtUsername;
@FXML
private TextField txtPassword;
@FXML
private Button btnHandle;
@FXML
private void handleButtonAction2(ActionEvent event) throws IOException {
String username= txtUsername.getText();
String password= txtPassword.getText();
if (username.equals("beyto") && password.equals("123")) {
alert.showTick();
switchpage.switchtoHomepage(event);
}
else if (username.equals(" ") || password.equals(" ")) {
alert.showError();
}
else{
alert.showError();
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}
Here is Login.fxml
<AnchorPane id="AnchorPane" prefHeight="564.0" prefWidth="1069.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="schoolmanagementsystem.LoginController">
<children>
<Label layoutX="600.0" layoutY="210.0" minHeight="16" minWidth="69" text="Username">
<font>
<Font size="16.0" />
</font></Label>
<TextField fx:id="txtUsername" layoutX="691.0" layoutY="207.0" prefHeight="31.0" prefWidth="186.0">
<font>
<Font size="15.0" />
</font>
</TextField>
<TextField fx:id="txtPassword" layoutX="691.0" layoutY="284.0">
<font>
<Font size="15.0" />
</font>
</TextField>
<Button fx:id="btnHandle" layoutX="721.0" layoutY="361.0" mnemonicParsing="false" onAction="#handleButtonAction2" opacity="0.96" prefHeight="31.0" prefWidth="125.0" text="Log in">
<font>
<Font size="13.0" />
</font>
</Button>
<Label layoutX="601.0" layoutY="287.0" minHeight="16" minWidth="69" text="Password">
<font>
<Font size="16.0" />
</font></Label>
<Label layoutX="750.0" layoutY="119.0" text="Log in">
<font>
<Font name="Calibri Bold" size="27.0" />
</font>
</Label>
<Line endX="174.80001831054688" endY="359.69287109375" layoutX="286.0" layoutY="206.0" opacity="0.11" startX="174.80001831054688" startY="-206.0" />
<ImageView fitHeight="200.0" fitWidth="227.0" layoutX="128.0" layoutY="161.0">
<image>
<Image url="@../../../../sms.png" />
</image>
<effect>
<Blend mode="SOFT_LIGHT" />
</effect>
</ImageView>
<ImageView fitHeight="40.0" fitWidth="37.0" layoutX="14.0" layoutY="513.0">
<image>
<Image url="@../java.png" />
</image>
</ImageView>
</children>