Fxweaver 无法加载 FXML 文件

问题描述 投票:0回答:1

**嗨,我只是想加载我的项目的登录页面,但每次都会出现此错误: **

“由net.rgielen.fxweaver.core.FxLoadException引起:无法加载FXML文件文件:/C:/Users/vinic/smrf/target/classes/br/edu/ifnmg/smrf/Apresentacao/Desktop/login。 fxml”。

后来又说:

“由以下原因引起:javafx.fxml.LoadException:未指定控制器。 /C:/Users/vinic/smrf/target/classes/br/edu/ifnmg/smrf/Apresentacao/Desktop/login.fxml:52"

**我的登录控制器:**

package br.edu.ifnmg.smrf.Apresentacao.Desktop;

import javafx.fxml.Initializable;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import br.edu.ifnmg.smrf.servicos.AutenticacaoServico;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.AnchorPane;
import net.rgielen.fxweaver.core.FxmlView;

@Service
@FxmlView("login.fxml")
public class LoginController extends Controller {

    @Autowired
    private AutenticacaoServico autenticacao;

    // @Autowired
    // private LogServico logs;

    @FXML
    private Button close;

    @FXML
    private TextField inpLoginEmail;

    @FXML
    private PasswordField inpLoginSenha;

    @FXML
    private Button loginBtn;

    @FXML
    private AnchorPane viewLogin;

    public LoginController() {

    }

    @FXML
    public void autenticar(Event e) {
        String login = inpLoginEmail.getText();
        String senha = inpLoginSenha.getText();

        if (autenticacao.autenticar(login, senha)) {
            //carregarScene(painelNovoUsuario, NovoUsuarioController.class);

            // Alert alert = new Alert(AlertType.INFORMATION, "deu certo", ButtonType.OK);
            // alert.showAndWait();

            // logs.registrar(LogNivel.Informacao, "Login", txtLogin.getText());

            // carregarScene(viewLogin, TelaPrincipalController.class);

            // alert.showAndWait();
        } else {
            // logs.registrar(LogNivel.Erro, "Login", txtLogin.getText());
            // Alert alert = new Alert(AlertType.CONFIRMATION, "Erro ao acessar o sistema.
            // Deseja sair?", ButtonType.NO, ButtonType.NO);
            // alert.showAndWait();

            Alert alert = new Alert(
                AlertType.WARNING,
                "Não foi possível acessar o sistema. Verifique se os dados informados estão corretos.",
                ButtonType.OK)
            ;
            alert.showAndWait();

        }
    }

    @FXML
    public void irParaNovoUsuario(Event e) {
        //carregarScene(painelNovoUsuario, NovoUsuarioController.class);
    }
}

我的登录FXML 文件:

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

<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?>


<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <AnchorPane prefHeight="200.0" prefWidth="200.0">
         <children>
            <AnchorPane layoutX="5.0" layoutY="2.0" prefHeight="400.0" prefWidth="306.0" styleClass="left-form" stylesheets="@lib/web/loginDesign.css">
               <children>
                  <ImageView fitHeight="400.0" fitWidth="324.0" layoutX="-24.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@images/SMRF.png" />
                     </image>
                  </ImageView>
               </children>
            </AnchorPane>
            <AnchorPane fx:id="viewLogin" layoutX="312.0" layoutY="3.0" prefHeight="400.0" prefWidth="300.0" styleClass="right-form" stylesheets="@lib/web/loginDesign.css">
               <children>
                  <Label layoutX="81.0" layoutY="57.0" stylesheets="@lib/web/loginDesign.css" text="Bem Vindo!" textFill="#256b51">
                     <font>
                        <Font name="Tahoma Bold" size="24.0" />
                     </font>
                  </Label>
                  <TextField fx:id="inpLoginEmail" layoutX="40.0" layoutY="153.0" prefHeight="30.0" prefWidth="220.0" promptText="Matrícula" styleClass="textfield" stylesheets="@lib/web/loginDesign.css" />
                  <Label layoutX="48.0" layoutY="126.0" text="Login:" textFill="#256b51">
                     <font>
                        <Font name="Tahoma Bold" size="14.0" />
                     </font>
                  </Label>
                  <PasswordField fx:id="inpLoginSenha" layoutX="39.0" layoutY="225.0" prefHeight="30.0" prefWidth="220.0" promptText="Sua senha de 6 dígitos" styleClass="textfield" stylesheets="@lib/web/loginDesign.css" />
                  <Label layoutX="44.0" layoutY="200.0" text="Senha: " textFill="#256b51">
                     <font>
                        <Font name="Tahoma Bold" size="14.0" />
                     </font>
                  </Label>
                  <Button fx:id="loginBtn" layoutX="39.0" layoutY="327.0" mnemonicParsing="false" prefHeight="40.0" prefWidth="220.0" styleClass="login-btn" stylesheets="@lib/web/loginDesign.css" text="Entrar">
                     <font>
                        <Font name="Tahoma Bold" size="18.0" />
                     </font>
                  </Button>
                  <Button fx:id="close" layoutX="249.0" layoutY="1.0" mnemonicParsing="false" onAction="#close" prefHeight="26.0" prefWidth="44.0" />
                  <FontAwesomeIcon glyphName="CLOSE" layoutX="265.0" layoutY="18.0" size="1.3em" />
               </children>
            </AnchorPane>
         </children>
      </AnchorPane>
   </children>
</StackPane>

我不知道我能做什么了

**我已经检查了 pom.fxml,重新加载了我的 VScode,检查了目录路径....但看起来没问题,我不知道它不再运行了。我刚刚添加了一个名为 AwesomeIcons 的库,它为视图提供了非常好的模板,它对于该项目变得非常重要...... **

java javafx containers fxml scenebuilder
1个回答
0
投票

在 FXML 文件的这一行中:

<Button fx:id="close" layoutX="249.0" layoutY="1.0" mnemonicParsing="false" onAction="#close" prefHeight="26.0" prefWidth="44.0" />

您指示当激活

close
按钮时应调用名为 close 的方法。因此,JavaFX 基础设施将在 FXML 文件中指示的控制器中查找方法
close
。但是,在您的 FXML 文件中没有控制器。您需要将其添加到“imports”之后的第一行[非空白]中,即

<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="br.edu.ifnmg.smrf.Apresentacao.Desktop.LoginController">
© www.soinside.com 2019 - 2024. All rights reserved.