0
我正在使用SceneBuilder來構建Java GUI應用程序。我試圖將控制器附加到我的fxml文件,所以我可以在我的應用程序中具有實際的功能。我應該提到它在這之前沒有錯誤地運行。當我連接控制器,我得到了這個:當我將控制器附加到我的fxml文件時,我得到一個constructLoadException
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at t9.htmleditor.MainApp.showMainGUI(MainApp.java:54)
at t9.htmleditor.MainApp.start(MainApp.java:24)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/1730989841.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/1051754451.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/50177904.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Can not set java.awt.Button field t9.htmleditor.view.ToolContoller.PageTitle to javafx.scene.control.Button
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)
at java.lang.reflect.Field.set(Unknown Source)
at javafx.fxml.FXMLLoader.injectFields(Unknown Source)
at javafx.fxml.FXMLLoader.access$1600(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processValue(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source)
at javafx.fxml.FXMLLoader.processStartElement(Unknown Source)
我無法解釋這一點,並找出哪裏出了問題。任何人都可以將我指向正確的方向嗎?
這裏是我的controlller:
package t9.projectName.view;
import java.awt.Button;
import t9.hprojectName.MainApp;
import javafx.fxml.FXML;
import javafx.scene.Group;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.AnchorPane;
public class ToolContoller {
@FXML
private Group ToolGroup;
@FXML
private AnchorPane TextTools;
@FXML
private Button Text;
@FXML
private Button TextHeader;
@FXML
private Button BackgroundColor;
@FXML
private Button Video;
@FXML
private Button PageTitle;
@FXML
private Button Templates;
@FXML
private Button Images;
// Reference to the main application.
private MainApp mainApp;
/**
* The constructor.
* The constructor is called before the initialize() method.
*/
public ToolContoller() {
}
/**
* Is called by the main application to give a reference back to itself.
*
* @param mainApp
*/
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
}
/**
* Called when the user clicks on the delete button.
*/
@FXML
private void handleTextButton() {
TextTools.setVisible(true);
}
}