Не могу решить ошибку, в javafx проекте [закрыт]

160
03 января 2020, 05:40
Закрыт. Этот вопрос не по теме. Ответы на него в данный момент не принимаются.

Хотите улучшить этот вопрос? Update the question so it's on-topic for Stack Overflow на русском.

Закрыт 9 месяцев назад.

        "C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.3\lib\idea_rt.jar=54027:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_191\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar;C:\Users\HP\Desktop\projects\Kursovoi_OOP\out\production\Kursovoi_OOP;C:\Program Files (x86)\MySQL\Connector J 8.0\mysql-connector-java-8.0.15.jar" sample.Main
        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:767)
        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$154(LauncherImpl.java:182)
            at java.lang.Thread.run(Thread.java:748)
        Caused by: javafx.fxml.LoadException: 
        /C:/Users/HP/Desktop/projects/Kursovoi_OOP/out/production/Kursovoi_OOP/sample/MainForm.fxml:8
            at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
            at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:103)
            at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:922)
            at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
            at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
            at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
            at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
            at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
            at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
            at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
            at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
            at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
            at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
            at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
            at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
            at sample.Main.start(Main.java:32)
            at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
            at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
            at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
            at java.security.AccessController.doPrivileged(Native Method)
            at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
            ... 1 more
        Caused by: java.lang.ClassNotFoundException: MainController.java
            at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
            at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:920)
            ... 22 more
        Exception running application sample.Main
        Process finished with exit code 1

    Main.java: 
        package sample;
    import javafx.application.Application;
    import javafx.fxml.FXMLLoader;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    import javafx.scene.control.Alert;
    import javafx.stage.Stage;
    import java.io.IOException;
    import java.sql.SQLException;
    public class Main extends Application {
        public static Stage stage;
        public static DatabaseHandler dbHandler = new DatabaseHandler();
        @Override
        public void start(Stage primaryStage) throws IOException  {
            //проверка соединения с БД
            try {
                DatabaseHandler.dbConnection = dbHandler.getDbConnection();
            } catch (ClassNotFoundException | SQLException e1) {
                Alert alert = MainController.alert(Alert.AlertType.INFORMATION, "Сообщение", "Соединение с БД не установлено");
                alert.showAndWait();
                return;
            }
            stage = primaryStage;
            Parent pane = FXMLLoader.load(getClass().getResource("MainForm.fxml"));
            Scene scene = new Scene(pane);
            primaryStage.setScene(scene);
            primaryStage.setTitle("Отдел кадров МММК");
            primaryStage.setHeight(700);
            primaryStage.setWidth(1000);
            primaryStage.show();
        }
        public static void main(String[] args) {
            launch(args);
        }
    }


    MainController.java :
        введите сpackage sample;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.fxml.FXML;
    import javafx.fxml.FXMLLoader;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    import javafx.scene.control.Alert;
    import javafx.scene.control.MenuItem;
    import javafx.stage.Stage;
    import javafx.stage.WindowEvent;
    import sample.Main;
    import java.io.IOException;
    public class MainController {
        @FXML
        void openStaffForm(ActionEvent event) throws IOException {
            //при выборе Сотрудники пункт меню делаем неактивным
            MenuItem mi = (MenuItem) event.getSource();
            mi.setDisable(true);
            Parent pane = FXMLLoader.load(getClass().getResource("StaffForm.fxml"));
            Scene scene = new Scene(pane);
            Stage childStage = new Stage();
            childStage.setScene(scene);
            childStage.initOwner(Main.stage);//окно будет выводиться поверх главного окна
            childStage.centerOnScreen();
            childStage.setWidth(400);
            childStage.setHeight(300);
            childStage.show();
            //обрабатываем закрытие окна
            childStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                public void handle(WindowEvent we) {
                    mi.setDisable(false);//пункт меню Сотрудники делаем активным
                }
            });
        }
        @FXML
        void openClientsForm(ActionEvent event) throws IOException {
            //при выборе Клиенты пункт меню делаем неактивным
            MenuItem mi = (MenuItem)event.getSource();
            mi.setDisable(true);
            Parent pane = FXMLLoader.load(getClass().getResource("SpecialityForm.fxml"));
            Scene scene = new Scene(pane);
            Stage childStage = new Stage();
            childStage.setScene(scene);
            childStage.initOwner(Main.stage);//окно будет выводиться поверх главного окна
            childStage.centerOnScreen();
            childStage.setWidth(400);
            childStage.setHeight(300);
            childStage.show();
            //обрабатываем закрытие окна
            childStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                public void handle(WindowEvent we) {
                    mi.setDisable(false);//пункт меню Специальности и группы делаем активным
                }
            });
        }
        //шаблон для информационных окон
        public static Alert alert(Alert.AlertType type, String title, String message) {
            Alert alert = new Alert(type);
            alert.setTitle(title);
            alert.setHeaderText("");
            alert.setContentText(message);
            return alert;
        }
    }


    database.properties:
        url = jdbc:mysql://127.0.0.1/kursovoi?serverTimezone=UTC
    username = root
    password = 12345


    MainForm.fxml:
        <?xml version="1.0" encoding="UTF-8"?>
    <?import javafx.scene.control.*?>
    <?import java.lang.*?>
    <?import javafx.scene.layout.*?>

    <BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="MainController.java">
       <top>
          <MenuBar BorderPane.alignment="CENTER">
            <menus>
              <Menu mnemonicParsing="false" text="Справочники">
                <items>
                  <MenuItem mnemonicParsing="false" onAction="#openStaffForm" text="Сотрудники" />
                      <MenuItem mnemonicParsing="false" onAction="#openClientsForm" text="Клиенты" />
                </items>
              </Menu>
              <Menu mnemonicParsing="false" text="Реставрация">
                <items>
                  <MenuItem mnemonicParsing="false" text="Delete" />
                </items>
              </Menu>
            </menus>
          </MenuBar>
       </top>
    </BorderPane>


DatabaseHandler.java: 
package sample;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class DatabaseHandler {
    public static Connection dbConnection;
    //подключиться к БД
    public Connection getDbConnection() throws SQLException, IOException, ClassNotFoundException {
        Properties props = new Properties();
        try(InputStream in = Files.newInputStream(Paths.get("src\\sample\\database.properties"))){
            props.load(in);
        }
        String url = props.getProperty("url");
        String username = props.getProperty("username");
        String password = props.getProperty("password");
        dbConnection = DriverManager.getConnection(url, username, password);
        return dbConnection;
    }
}
Answer 1

FXMLLoader не может загрузить MainForm.fxml, потому что не может найти класс MainController.java.

Попробуйте указать полное имя класса контроллера в файле MainForm.fxml, то есть fx:controller="sample.MainController"

READ ALSO
Аудит кода/проекта [закрыт]

Аудит кода/проекта [закрыт]

Хотите улучшить этот вопрос? Переформулируйте вопрос, чтобы он был сосредоточен только на одной проблеме, отредактировав его

158
Как лучше задать метод?

Как лучше задать метод?

В чём разница между v и view? Как лучше?

186
Получение местоположения Android

Получение местоположения Android

Задача реализовать получение местоположения (долготы и широты) при нажатии на buttonТо есть обновляется только при нажатии

198