Контроллер:
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.f xml:
<?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>
Ошибка:
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)
Я буду очень рад, если мы мог решить это. Что-то интересное, потому что он компилируется в Intellij без проблем, но когда я компилирую его в файл jar, а затем пытаюсь выполнить его, он показывает это. И я не знаю, что здесь добавить, я могу ответить на любые вопросы, если у вас есть.
Экран исключения
Дерево папок: QUIZ-> sr c -> Контроллер. java QUIZ-> sr c -> studSet.f xml
Я не могу открыть файл JAR с java -jar, потому что он показывает «Ошибка: не удалось найти или загрузить основной класс QUIZ_jar.jar ", хотя он компилируется в Intellij
Еще одна забавная вещь !!! Я просто переместил файл jar из папки «out» в основной каталог, и это сработало! Но проблема та же: я не могу вывести это оттуда.