找不到处理程序方法 - JavaFX

时间:2018-04-23 23:36:58

标签: java javafx

我在这个界面上遇到了一些麻烦,我有这个fxml文件:

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

<?import java.lang.String?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane id="AnchorPane" prefHeight="600.0" prefWidth="1000.0" stylesheets="@Stylesheets/styles.css" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="guichat.HomeController">
   <children>
      <AnchorPane layoutX="250.0" layoutY="64.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="32.0">
         <children>
            <AnchorPane maxWidth="64.0" minWidth="64.0" prefHeight="200.0" prefWidth="64.0" styleClass="sidebar" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
               <children>
                  <Button layoutY="2.0" maxHeight="64.0" maxWidth="64.0" minHeight="64.0" minWidth="64.0" mnemonicParsing="false" prefHeight="64.0" prefWidth="64.0" styleClass="sidebar-btn" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                     <font>
                        <Font name="Century Gothic Bold" size="13.0" />
                     </font>
                     <graphic>
                        <ImageView fitHeight="24.0" fitWidth="24.0" pickOnBounds="true" preserveRatio="true">
                           <image>
                              <Image url="@Assets/msg.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <cursor>
                        <Cursor fx:constant="HAND" />
                     </cursor>
                  </Button>
                  <Button layoutY="64.0" maxHeight="64.0" maxWidth="64.0" minHeight="64.0" minWidth="64.0" mnemonicParsing="false" prefHeight="64.0" prefWidth="64.0" styleClass="sidebar-btn">
                     <font>
                        <Font name="Century Gothic Bold" size="13.0" />
                     </font>
                     <graphic>
                        <ImageView fitHeight="24.0" fitWidth="24.0" pickOnBounds="true" preserveRatio="true">
                           <image>
                              <Image url="@Assets/addfriend.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <cursor>
                        <Cursor fx:constant="HAND" />
                     </cursor>
                  </Button>
                  <Button layoutX="-14.0" layoutY="136.0" maxHeight="64.0" maxWidth="64.0" minHeight="64.0" minWidth="64.0" mnemonicParsing="false" prefHeight="64.0" prefWidth="64.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="128.0">
                     <font>
                        <Font name="Century Gothic Bold" size="13.0" />
                     </font>
                     <graphic>
                        <ImageView fitHeight="24.0" fitWidth="24.0" pickOnBounds="true" preserveRatio="true">
                           <image>
                              <Image url="@Assets/addgroup.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <cursor>
                        <Cursor fx:constant="HAND" />
                     </cursor>
                     <styleClass>
                        <String fx:value="sidebar-btn" />
                        <String fx:value="sidebar-active" />
                     </styleClass>
                  </Button>
                  <Button fx:id="outBtn" layoutY="504.0" maxHeight="64.0" maxWidth="64.0" minHeight="64.0" minWidth="64.0" mnemonicParsing="false" onAction="#signOut" prefHeight="64.0" prefWidth="64.0" styleClass="sidebar-btn" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="504.0">
                     <font>
                        <Font name="Century Gothic Bold" size="13.0" />
                     </font>
                     <graphic>
                        <ImageView fitHeight="24.0" fitWidth="24.0" pickOnBounds="true" preserveRatio="true">
                           <image>
                              <Image url="@Assets/out.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <cursor>
                        <Cursor fx:constant="HAND" />
                     </cursor>
                  </Button>
                  <Button layoutY="192.0" maxHeight="64.0" maxWidth="64.0" minHeight="64.0" minWidth="64.0" mnemonicParsing="false" prefHeight="64.0" prefWidth="64.0" styleClass="sidebar-btn" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="192.0">
                     <font>
                        <Font name="Century Gothic Bold" size="13.0" />
                     </font>
                     <graphic>
                        <ImageView fitHeight="24.0" fitWidth="24.0" pickOnBounds="true" preserveRatio="true">
                           <image>
                              <Image url="@Assets/notification.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <cursor>
                        <Cursor fx:constant="HAND" />
                     </cursor>
                  </Button>
               </children>
            </AnchorPane>
            <AnchorPane layoutX="64.0" prefHeight="200.0" prefWidth="300.0" styleClass="group" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="64.0" AnchorPane.topAnchor="0.0">
               <children>
                  <AnchorPane prefHeight="64.0" prefWidth="236.0" styleClass="border-bottom" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                     <children>
                        <Label layoutX="95.0" layoutY="28.0" text="Crear Grupo" textFill="#f2f7f7">
                           <font>
                              <Font name="Century Gothic Bold" size="18.0" />
                           </font>
                        </Label>
                     </children>
                  </AnchorPane>
                  <AnchorPane layoutY="84.0" prefHeight="484.0" prefWidth="236.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="64.0">
                     <children>
                        <TextField layoutX="10.0" layoutY="166.0" prefHeight="32.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
                           <font>
                              <Font name="Century Gothic" size="12.0" />
                           </font>
                        </TextField>
                        <Label layoutX="10.0" layoutY="134.0" prefHeight="32.0" text="Nombre del Grupo:" textFill="#f2f7f7" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
                           <font>
                              <Font name="Century Gothic Bold" size="13.0" />
                           </font>
                        </Label>
                        <TextField layoutX="10.0" layoutY="261.0" prefHeight="32.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
                           <font>
                              <Font name="Century Gothic" size="12.0" />
                           </font>
                        </TextField>
                        <Label layoutX="10.0" layoutY="229.0" prefHeight="32.0" text="Creador:" textFill="#f2f7f7" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
                           <font>
                              <Font name="Century Gothic Bold" size="13.0" />
                           </font>
                        </Label>
                        <Button fx:id="createGroupBtn" layoutX="10.0" layoutY="339.0" maxHeight="32.0" minHeight="32.0" mnemonicParsing="false" onAction="#createGroup" prefHeight="32.0" styleClass="btn-green" text="CREAR GRUPO" textFill="#fffefe" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
                           <font>
                              <Font name="Century Gothic Bold" size="13.0" />
                           </font>
                        </Button>
                     </children>
                  </AnchorPane>
               </children>
            </AnchorPane>
         </children>
      </AnchorPane>
      <AnchorPane fx:id="headerBar" layoutX="10.0" layoutY="10.0" prefHeight="32.0" prefWidth="200.0" style="-fx-background-color: #303841;" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <children>
            <Button fx:id="closeWindowBtn" layoutX="968.0" layoutY="4.0" maxWidth="32.0" minWidth="32.0" mnemonicParsing="false" onAction="#handleCloseWindow" prefWidth="32.0" styleClass="close" text="x" textFill="WHITE" AnchorPane.bottomAnchor="1.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="-2.0">
               <font>
                  <Font name="Century Gothic Bold" size="13.0" />
               </font>
               <cursor>
                  <Cursor fx:constant="HAND" />
               </cursor>
            </Button>
            <Button fx:id="minimizeWindowBtn" layoutX="936.0" layoutY="4.0" maxWidth="32.0" minWidth="32.0" mnemonicParsing="false" onAction="#handleMinimizeWindow" prefWidth="32.0" styleClass="close" text="-" textFill="WHITE" AnchorPane.bottomAnchor="1.0" AnchorPane.rightAnchor="32.0" AnchorPane.topAnchor="-2.0">
               <font>
                  <Font name="Century Gothic Bold" size="13.0" />
               </font>
               <cursor>
                  <Cursor fx:constant="HAND" />
               </cursor>
            </Button>
         </children>
      </AnchorPane>
   </children>
</AnchorPane>

这是我的控制器,包含所有方法: 注意:所有函数都可以正常工作,只是createGroup方法不起作用。

package guichat;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

/**
 * FXML Controller class
 *
 * @author Wero
 */
public class GroupsController implements Initializable {


    @FXML private Button closeWindowBtn, minimizeWindowBtn, createGroupBtn, outBtn;


    @FXML
    public void handleCloseWindow(ActionEvent e){
        Stage stage = (Stage) closeWindowBtn.getScene().getWindow();
        stage.close();
    }


    @FXML
    public void handleMinimizeWindow(ActionEvent e){
        Stage stage = (Stage) minimizeWindowBtn.getScene().getWindow();
        stage.setIconified(true);
    }


    @FXML
    public void createGroup(ActionEvent e){
        try {
            FXMLLoader loader = new FXMLLoader(getClass().getResource("Home.fxml"));
            Stage stage = (Stage) outBtn.getScene().getWindow();
            Scene scene = new Scene(loader.load());
            stage.setScene(scene);
        }catch (IOException io){
            io.printStackTrace();
        }
    }


    @FXML
    public void signOut(ActionEvent e){
        try {
            FXMLLoader loader = new FXMLLoader(getClass().getResource("Login.fxml"));
            Stage stage = (Stage) outBtn.getScene().getWindow();
            Scene scene = new Scene(loader.load());
            stage.setScene(scene);
        }catch (IOException io){
            io.printStackTrace();
        }
    }

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        System.out.println("Interface ready!!");
    }    

}

好吧,我就是在mi界面中,用户可以发送消息,然后我尝试按下按钮转到“群组”界面,但netbeans给我这个错误:

 javafx.fxml.LoadException: Error resolving onAction='#createGroup', either the event handler is not in the Namespace or there is an error in the script.
file:/C:/Users/Wero/Documents/GitHub/cliente/GUIChat/dist/run1706281368/GUIChat.jar!/guichat/Groups.fxml:137

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at guichat.HomeController.goToCreateGroup(HomeController.java:112)
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.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)

我一直在阅读有关此错误的帖子,但它们对我不起作用,我正在使用Scene Builder来创建界面。有没有人知道为什么会出现这个错误?

0 个答案:

没有答案