0

I tried to add 3options for signup using the choice box in javafx and I write the code below to open 3 different windows for signup. From the signup windows i wanted to add a back button so that it returns to the homepage but when I click back button it shows error- Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

package Ayesha.Controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.shape.Arc;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class HomePageController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Label Appname;

    @FXML
    private Label Llogo;

    @FXML
    private Label Slogo;

    @FXML
    private ImageView appHomeImg;

    @FXML
    private Button contact;

    @FXML
    private Button dashboard;

    @FXML
    private Button SignUp;

    @FXML
    private Button login;

    @FXML
    private Arc logo;

    @FXML
    private ChoiceBox<String> typeOfUser;

    @FXML
    private Label welcomeText;

    @FXML
    void loginAction(ActionEvent event) throws IOException {
        Slogo.getScene().getWindow().hide();
        Stage logIN = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("/Ayesha/FXML/design.fxml"));
        Scene sc = new Scene(root);
        logIN.setScene(sc);
        logIN.show();
        logIN.setResizable(false);
    }

    @FXML
    void signUpAction(ActionEvent event) throws IOException {
        Slogo.getScene().getWindow().hide();
        Stage signup = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("/Ayesha/FXML/StudentSignUp.fxml"));
        Scene scene = new Scene(root);
        signup.setScene(scene);
        signup.setTitle("Student Signup Form");
        if(typeOfUser.getSelectionModel().getSelectedItem().equals("Student")){
             root = FXMLLoader.load(getClass().getResource("/Ayesha/FXML/StudentSignUp.fxml"));
             scene = new Scene(root);
            signup.setScene(scene);
            signup.setTitle("Student Signup Form");
        }
        if(typeOfUser.getSelectionModel().getSelectedItem().equals("Teacher")){
             root = FXMLLoader.load(getClass().getResource("/Ayesha/FXML/TeacherSignUp.fxml"));
             scene = new Scene(root);
            signup.setScene(scene);
            signup.setTitle("Teacher Signup Form");
        }
        if(typeOfUser.getSelectionModel().getSelectedItem().equals("Instructor")){
             root = FXMLLoader.load(getClass().getResource("/Ayesha/FXML/InstructorSignUp.fxml"));
             scene = new Scene(root);
            signup.setScene(scene);
            signup.setTitle("Instructor Signup Form");
        }
        signup.show();
        signup.setResizable(false);
    }

    /*@FXML
    void signUpAction(ActionEvent event) throws IOException {
        Slogo.getScene().getWindow().hide();
        Stage signup = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("/Ayesha/FXML/SignUp.fxml"));
        Scene scene = new Scene(root);
        signup.setScene(scene);
        signup.show();
        signup.setResizable(false);
    }*/

    @FXML
    void initialize() {
        typeOfUser.getItems().addAll("Student","Teacher","Instructor");
        typeOfUser.setValue("Student");
    }
}

errors

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml@18/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1857)
    at javafx.fxml@18/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1724)
    at javafx.base@18/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at javafx.base@18/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
    at javafx.base@18/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base@18/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base@18/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base@18/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@18/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@18/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@18/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@18/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@18/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base@18/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.base@18/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics@18/javafx.scene.Node.fireEvent(Node.java:8797)
    at javafx.controls@18/javafx.scene.control.Button.fire(Button.java:203)
    at javafx.controls@18/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:208)
    at javafx.controls@18/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
    at javafx.base@18/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
    at javafx.base@18/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at javafx.base@18/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
    at javafx.base@18/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base@18/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base@18/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base@18/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@18/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@18/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@18/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@18/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@18/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base@18/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base@18/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics@18/javafx.scene.Scene$MouseHandler.process(Scene.java:3881)
    at javafx.graphics@18/javafx.scene.Scene.processMouseEvent(Scene.java:1874)
    at javafx.graphics@18/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2607)
    at javafx.graphics@18/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
    at javafx.graphics@18/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics@18/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
    at javafx.graphics@18/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
    at javafx.graphics@18/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
    at javafx.graphics@18/com.sun.glass.ui.View.handleMouseEvent(View.java:551)
    at javafx.graphics@18/com.sun.glass.ui.View.notifyMouse(View.java:937)
    at javafx.graphics@18/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@18/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: 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:577)
    at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:77)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at javafx.base@18/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml@18/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)
    at javafx.fxml@18/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1852)
    ... 46 more
Caused by: java.lang.IllegalStateException: Location is not set.
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2541)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516)
    at ayesha/Ayesha.Controller.StudentSignUpController.backHome(StudentSignUpController.java:63)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    ... 53 more

Process finished with exit code 0
  • Show stacktrace . I think you should try with in Platform.runlater(() ->{...}); – Raw Apr 29 '22 at 08:10
  • Updated with error list @Raw – Ayesha Chowdhury Rimi Apr 29 '22 at 08:47
  • It's solved actually I misspelled the path – Ayesha Chowdhury Rimi Apr 29 '22 at 09:15
  • something in the resource look-up is wrong (see the duplicate for details) - if that doesn't help, provide a [mcve] (mind the __M__ - that is nothing unrelated, no fluff, a single controller with a single field - and reproducible - that is including application, fxml, controller) demonstrating the problem. Unrelated: stick to java naming convention when showing java code publicly, please. – kleopatra Apr 29 '22 at 09:17
  • Note the suggestion for using `Platform.runLater` would only be applicable if you had a multi-threaded app, which you don't (as far as I can tell). – jewelsea Apr 29 '22 at 19:11

0 Answers0