0

when I try to run my classe and enter my chef login panel informations using (java, eclipse, javaFX and scene builder) i got this exception.(this problem is only for redirectToChefReception(); part) here is my LoginPanelController class:

package application;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import java.io.IOException;
public class LoginPanelController {
    @FXML
    private TextField usernameField;
    @FXML
    private PasswordField passwordField;
    @FXML
    private Button loginButton;
    @FXML
    private void loginButtonClicked() {
        String username = usernameField.getText();
        String password = passwordField.getText();  
        // Perform login validation here
        if (username.equals("lahmidi") && password.equals("emp1")){
            redirectToServerReception();
        }
        else if(username.equals("zeroual") && password.equals("emp2")){
            redirectToChefReception();
        }
        
        else {
            showErrorMessage("Username or password is incorrect");
        }
    }
  
 public void redirectToServerReception() {
        try {
            // Load the FXML file for the reception panel
            FXMLLoader loader = new FXMLLoader(getClass().getResource("reception.fxml"));
            Parent root = loader.load();
            
            // Create a new scene for the reception panel
            Scene scene = new Scene(root);
            
            // Get the current stage
            Stage currentStage = (Stage) loginButton.getScene().getWindow();
            
            // Set the new scene on the current stage
            currentStage.setScene(scene);
            currentStage.setTitle("Reception");
            currentStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public void redirectToChefReception() {
        try {
            // Load the FXML file for the reception panel
            FXMLLoader loader = new FXMLLoader(getClass().getResource("application/receptionChef.fxml"));
            Parent root = loader.load();
            
            // Create a new scene for the reception panel
            Scene scene = new Scene(root);
            
            // Get the current stage
            Stage currentStage = (Stage) loginButton.getScene().getWindow();
            
            // Set the new scene on the current stage
            currentStage.setScene(scene);
            currentStage.setTitle("Reception");
            currentStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void showErrorMessage(String message) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Login Error");
        alert.setHeaderText(null);
        alert.setContentText(message);
        alert.showAndWait();
    }
}

and my receptionChef.fxml file:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="650.0" prefWidth="1063.0" style="-fx-background-color: #ffffff;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Reception2Controller">
   <children>
      <Label layoutX="51.0" layoutY="45.0" text="Dish name" />
      <TextField fx:id="dishNameTextField" layoutX="201.0" layoutY="189.0" />
      
      <Label layoutX="51.0" layoutY="189.0" text="price" />
      <TextField fx:id="priceTextField" layoutX="201.0" layoutY="37.0" />
      
      <Label layoutX="51.0" layoutY="113.0" text="category" />
      <ComboBox fx:id="categoryBox" layoutX="203.0" layoutY="113.0" prefHeight="50.0" prefWidth="286.0" />

      <Button fx:id="addButton" layoutX="111.0" layoutY="281.0" mnemonicParsing="false" onAction="#addDish" text="add" />
      <Button fx:id="deleteButton" layoutX="219.0" layoutY="281.0" mnemonicParsing="false" onAction="#deleteDish" text="delete" />  
      <Button fx:id="editButton" layoutX="354.0" layoutY="281.0" mnemonicParsing="false" onAction="#editDish" text="edit" />
      <Button fx:id="saveButton" layoutX="524.0" layoutY="281.0" mnemonicParsing="false" onAction="#saveDish" text="save" />
      <TableView layoutX="51.0" layoutY="345.0" prefHeight="291.0" prefWidth="646.0">
        <columns>
          <TableColumn fx:id="nameColumn" prefWidth="341.0" text="name" />
          <TableColumn fx:id="categoryColumn" prefWidth="212.0" text="category" />
          <TableColumn fx:id="priceColumn" prefWidth="92.0" text="price" />
        </columns>
      </TableView>
      <ImageView fitHeight="454.0" fitWidth="326.0" layoutX="760.0" layoutY="196.0" pickOnBounds="true" preserveRatio="true">
         <image>
            <Image url="@../../../../OneDrive/Bureau/Nouveau%20dossier/logo9.jpg" />
         </image>
      </ImageView>
      <ImageView fitHeight="224.0" fitWidth="339.0" layoutX="755.0" layoutY="1.0" pickOnBounds="true" preserveRatio="true">
         <image>
            <Image url="@../../../../OneDrive/Bureau/Nouveau%20dossier/pasta.jpg" />
         </image>
      </ImageView>
   </children>
</AnchorPane>

i tried to specify the path of my receptionChef.fxml by ("nameOfPackage/receptionChef.fxml") but no result I got a plenty of errors and exception:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml@20.0.1/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1858)
    at javafx.fxml@20.0.1/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1726)
    at javafx.base@20.0.1/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at javafx.base@20.0.1/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
    at javafx.base@20.0.1/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
    at javafx.base@20.0.1/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base@20.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base@20.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@20.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@20.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@20.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@20.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@20.0.1/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base@20.0.1/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.base@20.0.1/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics@20.0.1/javafx.scene.Node.fireEvent(Node.java:8944)
    at javafx.controls@20.0.1/javafx.scene.control.Button.fire(Button.java:203)
    at javafx.controls@20.0.1/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:207)
    at javafx.controls@20.0.1/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
    at javafx.base@20.0.1/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
    at javafx.base@20.0.1/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at javafx.base@20.0.1/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
    at javafx.base@20.0.1/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
    at javafx.base@20.0.1/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base@20.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base@20.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@20.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@20.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@20.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@20.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@20.0.1/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base@20.0.1/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base@20.0.1/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics@20.0.1/javafx.scene.Scene$MouseHandler.process(Scene.java:3980)
    at javafx.graphics@20.0.1/javafx.scene.Scene.processMouseEvent(Scene.java:1890)
    at javafx.graphics@20.0.1/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2704)
    at javafx.graphics@20.0.1/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
    at javafx.graphics@20.0.1/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics@20.0.1/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
    at javafx.graphics@20.0.1/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
    at javafx.graphics@20.0.1/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
    at javafx.graphics@20.0.1/com.sun.glass.ui.View.handleMouseEvent(View.java:551)
    at javafx.graphics@20.0.1/com.sun.glass.ui.View.notifyMouse(View.java:937)
    at javafx.graphics@20.0.1/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@20.0.1/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)
    at java.base/java.lang.Thread.run(Thread.java:833)
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:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:72)
    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:568)
    at javafx.base@20.0.1/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:270)
    at javafx.fxml@20.0.1/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)
    at javafx.fxml@20.0.1/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1855)
    ... 46 more
Caused by: java.lang.IllegalStateException: Location is not set.
    at javafx.fxml@20.0.1/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2556)
    at javafx.fxml@20.0.1/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2531)
    at application.LoginPanelController.redirectToChefReception(LoginPanelController.java:68)
    at application.LoginPanelController.loginButtonClicked(LoginPanelController.java:35)
    ... 57 more
Manal L
  • 9
  • 3

0 Answers0