0

Controller:

package sample;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.Scanner;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.stage.Stage;

public class Controller {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button studentSignInBut;

    @FXML
    private TextField logiinText;

    @FXML
    private PasswordField passText;

    @FXML
    private Button signInBut;

    @FXML
    void e4bbbb(ActionEvent event) {

    }



    @FXML
    void initialize() {
        studentSignInBut.setOnAction(e -> {
                try {
                    Parent parent = FXMLLoader.load(getClass().getResource("studSet.fxml"));
                    Scene scene = new Scene(parent);
                    Stage stage = (Stage)((Node)e.getSource()).getScene().getWindow();
                    stage.setScene(scene);
                    stage.show();
                    stage.setResizable(false);
                } catch (Exception ex) {
                    ex.printStackTrace();

                    String error = "";
                    StackTraceElement[] list = ex.getStackTrace();
                    for (StackTraceElement i : list) {
                        error+=i.toString()+"\n";
                    }
                    Pane p = new Pane();
                    p.getChildren().add(new TextArea(error));
                    ScrollPane sp = new ScrollPane(p);
                    Stage st = new Stage();
                    Scene sc = new Scene(sp);
                    st.setScene(sc);
                    st.show();

                    Alert errorAlert = new Alert(Alert.AlertType.ERROR);
                    errorAlert.setHeaderText(ex.getClass().getName());
                    errorAlert.setContentText("To String: "+ex.toString()+"\n"+error
                    );
                    errorAlert.getDialogPane().setPrefWidth(1000.0);
                    errorAlert.showAndWait();
                }
        });
        signInBut.setOnAction(e -> {
            String login = logiinText.getText();
            String pass = passText.getText();
            File file = new File("src\\info\\AdminPassword.txt");
            try {
                Scanner sc = new Scanner(file);
                String pas = null;
                if (sc.hasNext()) {
                    String log = sc.next();
                    pas = sc.next();

                    if (login.equals(log) && pass.equals(pas)) {
                        System.out.println("Admin");


                        Parent parent = FXMLLoader.load(getClass().getResource("app.fxml"));
                        Scene scene = new Scene(parent);
                        Stage stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
                        stage.setScene(scene);
                        stage.show();
                        stage.setResizable(false);

                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                File currentDirectory = new File("");
//                File cur = new File(Controller.class.getProtectionDomain().getCodeSource().getLocation()
//                        .toURI()).getPath();
//                System.out.println(currentDirectory.getCanonicalPath());
//                System.out.println(currentDirectory.getAbsolutePath());
                Alert errorAlert = new Alert(Alert.AlertType.ERROR);
                errorAlert.setHeaderText(ex.getClass().getName());
                errorAlert.setContentText("To String: "+ex.toString()+"\nMessage: "+ex.getMessage()+"\nCause: "+ex.getCause()+"\nStackTrace: "
                        +ex.getStackTrace()+"\n\n\n"+System.getProperty("user.dir")+"\n\n\n"+currentDirectory.getAbsolutePath());
                errorAlert.showAndWait();
            }


        });
    }
}

studSet.fxml:

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

<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="700.0" style="-fx-background-color: #2e3348;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.studSetController">
    <children>
        <AnchorPane layoutY="109.0" prefHeight="291.0" prefWidth="700.0" style="-fx-background-color: #fafafa;">
         <children>
            <TextField fx:id="studName" layoutX="14.0" layoutY="14.0" prefHeight="35.0" prefWidth="303.0" promptText="Имя" />
            <TextField fx:id="studSurname" layoutX="14.0" layoutY="55.0" prefHeight="35.0" prefWidth="303.0" promptText="Фамилия" />
            <ComboBox fx:id="subjectName" layoutX="14.0" layoutY="98.0" prefHeight="25.0" prefWidth="303.0" promptText="Предмет" style="-fx-background-color: orange;" visibleRowCount="5" />
            <ComboBox fx:id="numOfQuestions" layoutX="14.0" layoutY="135.0" prefHeight="25.0" prefWidth="303.0" promptText="Колличество вопросов" style="-fx-background-color: orange;" visibleRowCount="5" />
            <ListView fx:id="subjectList" layoutX="331.0" layoutY="14.0" prefHeight="267.0" prefWidth="362.0" />
            <CheckBox fx:id="hintOnButton" layoutX="115.0" layoutY="181.0" mnemonicParsing="false" text="Подсказки" />
            <Button fx:id="backBut" layoutX="8.0" layoutY="248.0" mnemonicParsing="false" style="-fx-background-color: orange;" text="Назад" textFill="WHITE">
               <font>
                  <Font name="Comic Sans MS" size="16.0" />
               </font>
            </Button>
         </children>
        </AnchorPane>
        <Label layoutX="212.0" layoutY="14.0" text="Настройка" textFill="WHITE">
            <font>
                <Font name="Comic Sans MS" size="55.0" />
            </font>
        </Label>
      <Button fx:id="startBut" layoutX="571.0" layoutY="18.0" mnemonicParsing="false" style="-fx-background-color: orange;" text="Начать Тест" textFill="WHITE">
         <font>
            <Font name="Comic Sans MS" size="16.0" />
         </font>
      </Button>
    </children>
</AnchorPane>

The error:

javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2571)
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
sample.Controller.lambda$initialize$0(Controller.java:53)
com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
javafx.event.Event.fireEvent(Event.java:198)
javafx.scene.Node.fireEvent(Node.java:8411)
javafx.scene.control.Button.fire(Button.java:185)
com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
javafx.event.Event.fireEvent(Event.java:198)
javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
java.security.AccessController.doPrivileged(Native Method)
com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:432)
com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410)
com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
com.sun.glass.ui.View.handleMouseEvent(View.java:555)
com.sun.glass.ui.View.notifyMouse(View.java:937)
com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
java.lang.Thread.run(Unknown Source)

I will be very happy, if we could solve this. Kinda interesting, because it compiles in Intellij without problems, but when I compile it to jar file, and then try to execute it, it shows this. And I don't know what to add here, I can answer any questions if you have.

Screen of exception

Folder tree: QUIZ->src->Controller.java QUIZ->src->studSet.fxml

I cannot open the jar file with java -jar, because it shows "Error: Could not find or load main class QUIZ_jar.jar", although it compiles in Intellij

Another funny thing!!! I just moved the jar file from "out" folder to the main directory and it worked! But the problem is the same: I can't move it out of there.

Adil Akhmetov
  • 121
  • 1
  • 1
  • 7
  • 2
    That does not seem to be the entire [stack trace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors) (for one, it's missing the actual exception/message). Please [edit] your question to provide the complete error message. – Slaw Feb 10 '20 at 18:42
  • Because I get it only in compiled javafx app, so there is no console where I can print exception message. Is there a way to open cmd in javafx, so I can show you full exception message? – Adil Akhmetov Feb 10 '20 at 20:20
  • Launch the application from the command line (e.g. `java -jar [args...]`). – Slaw Feb 10 '20 at 20:23
  • In addition to Slaws recommendation it would be most convenient to redirect stderr to a file: `java -jar myjar.jar 2>error.txt` (assuming a runnable jar) Be sure to include the bottommost `Caused by` part; that one usually contains the most valuable info... – fabian Feb 10 '20 at 22:52
  • Very interesting! It doesn't execute and it shows "Error: Could not find or load main class QUIZ_jar.jar", although there is a main class and manifest – Adil Akhmetov Feb 11 '20 at 08:06

1 Answers1

-1

the controller seems to be fine so far. the problem is probably how the fxml file is loaded (or there are problems with the file).

how do you call your scene? maybe this might work:

FXMLLoader loadFrame = new FXMLLoader(YOURCLASS.class.getClassLoader().getResource("com/app/resources/Frame.fxml"));
            Parent mainRoot = loadFrame.load();
Bart Hofma
  • 644
  • 5
  • 19
papalulu
  • 78
  • 6
  • as incomplete as the question is, please don't invent context ( there is no _Frame.fxml_ mentoned anywhere). – kleopatra Feb 11 '20 at 00:47