我有一个使用 Netbeans 和 JavaFx Scene Builder 构建的 JavaFx 项目。
有 3 个文件:Main Class 文件、FXML 文件和控制器。
现在,问题是我试图从以前的项目中复制和粘贴早期的 GUI JXML 文件,但是当我这样做时,项目将无法运行。更改控制器的 URL 没有帮助。
在我进行复制粘贴之前,一切都运行良好。
这些文件是:
Sample.FXML -> The orriginal GUI
SampleController.java -> The Controller class
Home.FXML -> The FXML file whose structure is to be copied to orriginal Sample.FXML
以下是文件:
Sample.FXML (复制前)
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="wakiliproject.SampleController">
<children>
<Button layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="button" />
<Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" fx:id="label" />
</children>
</AnchorPane>
SampleController.java
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
public class SampleController implements Initializable {
@FXML
private Label label;
@FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
label.setText("Hello World!");
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
主页.FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="624.0" prefWidth="900.0" styleClass="AnchorPane" xmlns:fx="http://javafx.com/fxml" fx:controller="wakiliproject.SampleController">
<children>
<Pane id="wrapperPane" prefHeight="600.0" prefWidth="700.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Pane fx:id="top" layoutX="-1.0" prefWidth="879.0" styleClass="appNav">
<children>
<HBox id="HBox" alignment="CENTER" layoutX="12.0" layoutY="6.0" spacing="10.0">
<children>
<Label prefHeight="32.0" prefWidth="32.0" styleClass="titleBarHome" />
<Label prefHeight="32.0" prefWidth="32.0" styleClass="titleBarPublisher" />
<Label prefHeight="32.0" prefWidth="32.0" styleClass="titleBarTools" />
</children>
</HBox>
<HBox id="HBox" alignment="CENTER" layoutX="667.0" layoutY="9.0" prefHeight="32.0" prefWidth="197.9998779296875" spacing="5.0">
<children>
<TextField prefWidth="200.0" styleClass="searchTextField" />
</children>
</HBox>
</children>
</Pane>
<Pane id="leftNav" layoutX="14.0" layoutY="52.0" prefHeight="511.999977929685" prefWidth="652.0" styleClass="centerPane">
<children>
<VBox id="VBox" alignment="CENTER" layoutX="38.0" layoutY="21.0" spacing="5.0">
<children>
<Label styleClass="centerPaneNavLeft" text="Accounts" />
<Label styleClass="centerPaneNavLeft" text="Cases" />
<Label styleClass="centerPaneNavLeft" text="Callender" />
<Label styleClass="centerPaneNavLeft" text="Matters" />
</children>
</VBox>
<VBox alignment="CENTER" layoutX="7.0" layoutY="110.0" spacing="5.0" styleClass="leftVBoxProfile">
<children>
<Label styleClass="centerPaneNavLeft" text="Profile and settings" />
<Label styleClass="centerPaneNavLeft" text="Firm staff" />
<Label styleClass="centerPaneNavLeft" text="Firm Interns" />
<Label styleClass="centerPaneNavLeft" text="Affiliates Firms" />
</children>
</VBox>
<Pane id="contentPane" layoutX="126.0" layoutY="21.0" prefHeight="436.0" prefWidth="525.999977929685" styleClass="centerPaneCct">
<children>
<HBox id="HBox" alignment="CENTER" layoutX="14.0" spacing="10.0">
<children>
<Label minHeight="32.0" minWidth="32.0" styleClass="centerMail" />
</children>
</HBox>
<Label layoutX="253.0" layoutY="8.0" styleClass="centerNotes" text="NOTES" />
<Pane fx:id="homeContentDisplay" layoutY="32.0" prefHeight="404.0" prefWidth="526.0">
<children>
<VBox id="VBox" alignment="BASELINE_LEFT" layoutX="14.0" layoutY="15.0" prefWidth="498.0" spacing="5.0" styleClass="centerPaneCctHomeNotifierVWrapper">
<children>
<Label styleClass="centerPaneCctHomeNotifierTtl" text="Notifications" />
<Label styleClass="centerPaneCctHomeNotifierNone" text="none listed" />
</children>
</VBox>
<VBox id="VBox" alignment="BASELINE_LEFT" layoutX="14.0" layoutY="62.0" prefWidth="498.0" spacing="5.0" styleClass="centerPaneCctHomeNotifierVWrapper">
<children>
<Label fx:id="label" styleClass="centerPaneCctHomeNotifierTtl" text="Activities today" visible="false" />
<Label styleClass="centerPaneCctHomeNotifierNone" text="none listed" />
</children>
</VBox>
<HBox id="HBox" alignment="CENTER" layoutX="435.0" layoutY="342.0" spacing="5.0" styleClass="centerSocialTabsOnlineHWrapper">
<children>
<Label prefHeight="24.0" prefWidth="24.0" styleClass="centerSocialTabsOnline" />
<Label prefHeight="24.0" prefWidth="24.0" styleClass="centerSocialTabsBlogs" />
<Label prefHeight="24.0" prefWidth="24.0" styleClass="centerSocialTabsQA" />
</children>
</HBox>
<Label layoutX="14.0" layoutY="109.0" styleClass="centerPaneKIWI" text="KIWI" />
<TextField fx:id="KIWITextField" layoutX="14.0" layoutY="134.0" prefHeight="42.0" prefWidth="498.0" styleClass="HomeKIWI" />
<Label id="labelShows" fx:id="GoKIWI" alignment="CENTER" layoutX="421.0" layoutY="176.0" prefWidth="91.0" styleClass="centerPaneKIWIPost" text="Post KIWI" />
<Label layoutX="14.0" layoutY="202.0" prefWidth="498.0" styleClass="centerPaneKIWIPostStatus" text="No KIWIs posted yet" />
<Pane layoutY="315.0" prefHeight="89.0" prefWidth="435.0" styleClass="footerFilesPane">
<children>
<Label layoutX="14.0" layoutY="14.0" styleClass="footerFilingNone" text="No files from this firm attached to Wakili yet." />
<Label layoutX="14.0" layoutY="36.0" styleClass="footerFilingNew" text="Attach new file here" />
<Label layoutX="397.0" layoutY="30.0" prefHeight="24.0" prefWidth="24.0" styleClass="footerFilingHelp" />
</children>
</Pane>
<Label layoutX="57.0" layoutY="-32.0" minHeight="32.0" minWidth="32.0" styleClass="centerContacts" />
</children>
</Pane>
<Pane fx:id="page2ContentDisplay" layoutY="32.0" prefHeight="404.0" prefWidth="526.0" visible="false">
<children>
<Label layoutX="14.0" layoutY="14.0" onMouseClicked="#handleButtonActionShowHome" text="Page 2" />
</children>
</Pane>
</children>
</Pane>
<Pane layoutX="-5.0" layoutY="457.0" prefWidth="656.999977929685">
<children>
<HBox id="HBox" alignment="CENTER" layoutX="-6.0" layoutY="12.0" prefWidth="336.0" spacing="20.0">
<children>
<Label alignment="BOTTOM_CENTER" prefHeight="40.0" styleClass="footerDocuments" text="Documents" />
<Label alignment="BOTTOM_CENTER" prefHeight="40.0" styleClass="footerMasterTables" text="Master Tables" />
<Label alignment="BOTTOM_CENTER" prefHeight="40.0" styleClass="footerFiling" text="Modules" />
</children>
</HBox>
</children>
</Pane>
<Label alignment="CENTER" layoutX="10.0" layoutY="222.0" prefWidth="111.0" styleClass="leftPanePersonalArea" text="My personal area" />
<VBox id="VBox" alignment="CENTER" layoutX="40.0" layoutY="250.0" spacing="5.0">
<children>
<Label styleClass="leftPanePersonalAreaLinks" text="My profile" />
<Label styleClass="leftPanePersonalAreaLinks" text="Wakili forums" />
<Label styleClass="leftPanePersonalAreaLinks" text="Shared data" />
</children>
</VBox>
</children>
<padding>
<Insets right="10.0" />
</padding>
</Pane>
<VBox id="VBox" alignment="CENTER" layoutX="710.0" layoutY="63.0" spacing="5.0" styleClass="rightPaneBillTaxVBox">
<children>
<Label styleClass="centerPaneNavLeft" text="Billing and Tax" />
<Label styleClass="centerPaneNavLeft" text="Payment management" />
</children>
</VBox>
<Pane layoutX="666.0" layoutY="107.0" prefHeight="404.0" prefWidth="197.99990000000253" styleClass="rightPane">
<children>
<Label layoutX="14.0" layoutY="14.0" styleClass="firmTitle" text="Kirundi & co. Advocates" />
<Label layoutX="14.0" layoutY="43.0" prefHeight="32.0" styleClass="rightPaneBackUp" text="Back-up firm data online" />
<HBox id="HBox" alignment="CENTER" layoutX="12.0" layoutY="94.0" spacing="10.0" styleClass="rightPaneKSLLSKHWrapper">
<children>
<Label styleClass="rightPaneKSLLSK" text="LSK" />
<Label styleClass="rightPaneKSLLSK" text="KSL">
<HBox.margin>
<Insets />
</HBox.margin>
</Label>
</children>
</HBox>
<Label layoutX="14.0" layoutY="120.0" styleClass="rightPaneTheCourts" text="The courts" />
<VBox id="VBox" alignment="CENTER_LEFT" layoutX="66.0" layoutY="143.0" spacing="5.0">
<children>
<Label styleClass="rightPaneTheCourtsLinks" text="Announcements" />
<Label styleClass="rightPaneTheCourtsLinks" text="Popular cases" />
</children>
</VBox>
<Label layoutX="50.0" layoutY="75.0" styleClass="rightPaneFirmWebsite" text="Go to firm website" />
</children>
</Pane>
<Label layoutX="746.0" layoutY="511.0" styleClass="footerCAMPORey" text="CAMP - ORey" />
</children>
</Pane>
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<stylesheets>
<URL value="@../Styling/Buttons.css" />
<URL value="@../Styling/Direction.css" />
<URL value="@../Styling/Labels.css" />
<URL value="@../Styling/Panes.css" />
<URL value="@../Styling/Text.css" />
<URL value="@../Styling/TextArea.css" />
</stylesheets>
</AnchorPane>
Sample.FXML (从 Home.FXML 复制粘贴后)
*Identical to home above*
更新:
错误信息:
Controller method "handleButtonActionShowHome" not found.
file:/D:/xampp/htdocs/Jive/WakiliProject/dist/WakiliProject.jar!/wakiliproject/Home.fxml:94
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:492)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:589)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2430)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2136)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2744)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2723)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2709)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2696)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2685)
at wakiliproject.WakiliProject.start(WakiliProject.java:13)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:724)
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.javafx.main.Main.launchApp(Main.java:642)
at com.javafx.main.Main.main(Main.java:805)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:724)
Caused by: javafx.fxml.LoadException: Controller method "handleButtonActionShowHome" not found.
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:492)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:589)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2430)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2136)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2744)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2723)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2709)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2696)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2685)
at wakiliproject.WakiliProject.start(WakiliProject.java:13)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
... 1 more
Java Result: 1
jfxsa-run:
BUILD SUCCESSFUL (total time: 52 seconds)