Mi problema es el siguiente.
Estoy con mi primer contacto con FXML pero me pasa una cosa muy rara, creo un Button y le pongo el texto Pulsar, hasta ahi todo bien, le doy a ejecutar y me sale lapantallita. El siguiente paso es meterle una accion al boton y elijo el onAction y lo pongo en el FXML quedando el codigo de la siguiente manera:
Código XML:
Ver original
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.image.*?> <?import javafx.scene.control.*?> <?import java.lang.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.AnchorPane?> <AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <children> <AnchorPane layoutX="-147.0" layoutY="-237.0" prefHeight="200.0" prefWidth="200.0" /> <AnchorPane prefHeight="370.0" prefWidth="336.0"> <children> <Button fx:id="btnPulsar" layoutX="142.0" layoutY="272.0" mnemonicParsing="false" onAction="#Pulsar" text="Pulsar" /> </children> </AnchorPane> </children> </AnchorPane>
En cuanto pongo ese onAction y lo intento ejecutar me da un error del constructor que es el siguiente:
javafx.fxml.LoadException: No controller specified.
/C:/Users/_Ivan_/workspace/Hola%20Mundo/bin/application/Hola_Mundo.fxml:14
at javafx.fxml.FXMLLoader.constructLoadException(Unkn own Source)
at javafx.fxml.FXMLLoader.access$100(Unknown Source)
at javafx.fxml.FXMLLoader$Element.getControllerMethod Handle(Unknown Source)
at javafx.fxml.FXMLLoader$Element.processEventHandler Attributes(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processEndElem ent(Unknown Source)
at javafx.fxml.FXMLLoader.processEndElement(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at application.Main.start(Main.java:29)
at com.sun.javafx.application.LauncherImpl.lambda$lau nchApplication1$163(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$run AndWait$176(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$nul l$174(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$run Later$175(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run( Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Nativ e Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$14 9(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Y en el Main.java tengo lo siguiente:
Código Java:
Ver original
package application; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.stage.Stage; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.BorderPane; public class Main extends Application { @FXML @FXML { btnPulsar.setText("Hola"); } @Override public void start(Stage primaryStage) { try { Parent parent = FXMLLoader.load(getClass().getResource("Hola_Mundo.fxml")); Scene scene = new Scene(parent); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); e.printStackTrace(); } } launch(args); } }
No se como so