@bruno.daniel escreveu:
Estou começando os estudos em JavaFX utilizando a ide Netbeans + SceneBuilder em conjunto e logo no primeiro projeto estou enfrentando um erro que não consigo decifrar.
Criei um "Novo Projeto >>> Aplicação FXML" e utilizei o SceneBuilder apenas para dar nomes (id's) aos dois componentes contidos na tela, um botão e um label.
Porem ao executar a aplicação tem sido exibido o seguinte erro:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication6(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at teste.Teste.start(Teste.java:22)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication13(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait6(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null4(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater5(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null9(WinApplication.java:191)
... 1 more
Exception running application teste.Teste
C:\Users\ALLINONE\Documents\NetBeansProjects\Teste\nbproject\build-impl.xml:1051: The following error occurred while executing this line:
C:\Users\ALLINONE\Documents\NetBeansProjects\Teste\nbproject\build-impl.xml:805: Java returned: 1
FALHA NA CONSTRUÇÃO (tempo total: 7 segundos)O meu projeto tem apenas a classe Principal chamada Teste com o seguinte código:
package teste; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; /** * * @author ALLINONE */ public class Teste extends Application { @Override public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml")); // Scene scene = new Scene(root); stage.setScene(new Scene(root)); stage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }
E a classe Control:
package teste; import java.net.URL; import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.input.MouseEvent; public class FXMLDocumentController implements Initializable { @FXML private Button btClick; @FXML private Label lbTexto; @FXML private void handleButtonAction(ActionEvent event) { System.out.println("You clicked me!"); lbTexto.setText("Hello World!"); } @Override public void initialize(URL url, ResourceBundle rb) { } @FXML private void handleButtonAction(MouseEvent event) { System.out.println("You clicked me!"); lbTexto.setText("Hello World!"); } }
Mensagens: 1
Participantes: 1