簡體   English   中英

當我將控制器附加到我的fxml文件時,我得到一個ConstructLoadException

[英]When I attach a controller to my fxml file, I get a constructLoadException

我正在使用SceneBuilder構建Java GUI應用程序。 我試圖將Controller附加到我的fxml文件,所以我可以在應用程序中使用實際功能。 我應該提到的是,在此之前它沒有任何錯誤。 當我連接控制器時,我得到了:

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)

我無法解釋這一點並弄清楚出了什么問題。 誰能指出我正確的方向?

這是我的控制者:

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);
}


}

問題出在您的進口商品上。 在您的控制器中,您有:

import java.awt.Button;

但是您在JavaFX中,請使用:

import  javafx.scene.control.Button

stacktrace上的這一行告訴您發生了什么

引起原因:java.lang.IllegalArgumentException:無法將java.awt.Button字段t9.htmleditor.view.ToolContoller.PageTitle設置為javafx.scene.control.Button

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM