Reputation: 406
I'm using SceneBuilder to building a Java GUI Application. I tried to attach a Controller to my fxml file, so I could have actual functionality in my application. I should mention that it was running with no errors prior to this. When I attached the controller, I got this:
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)
I am nowhere near being able to interpret this and figure out what went wrong. Can anyone point me in the right direction?
Here's my 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);
}
}
Upvotes: 0
Views: 2254
Reputation: 5032
The problem is on your imports. in your controller you have :
import java.awt.Button;
But you are in JavaFX so use :
import javafx.scene.control.Button
This line on your stacktrace tell you what happened
Caused by: java.lang.IllegalArgumentException: Can not set java.awt.Button field t9.htmleditor.view.ToolContoller.PageTitle to javafx.scene.control.Button
Upvotes: 2