Versão atual:

Erro na execução de Aplicação JavaFX por FXML gerado pelo Scene Builder

Olá pessoal,

minha aplicação JavaFX está quebrando quando executo a partir do FXML gerado pelo Scene Builder.

Tenho:

Java 8 Update 111 (64-bit)

Java SE Development Kit 8 Update 111 (64-bit)

NetBeans IDE 8.2

SceneBuilder 8.5.0 (64-bit) do site da Gluon

Eis o erro:

ant -f "C:\\Users\\Carlos Vinicius\\Documents\\NetBeansProjects\\JavaFXApplication2" -Djavac.includes=javafxapplication2/JavaFXApplication2.java -Dnb.internal.action.name=run.single -Drun.class=javafxapplication2.JavaFXApplication2 run-single
init:
Deleting: C:\Users\Carlos Vinicius\Documents\NetBeansProjects\JavaFXApplication2\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\Carlos Vinicius\Documents\NetBeansProjects\JavaFXApplication2\build\built-jar.properties
Compiling 1 source file to C:\Users\Carlos Vinicius\Documents\NetBeansProjects\JavaFXApplication2\build\classes
compile-single:
run-single:
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:498)
    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:498)
    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$launchApplication$155(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 javafxapplication2.JavaFXApplication2.start(JavaFXApplication2.java:22)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$null$148(WinApplication.java:191)
    ... 1 more
Exception running application javafxapplication2.JavaFXApplication2
C:\Users\Carlos Vinicius\Documents\NetBeansProjects\JavaFXApplication2\nbproject\build-impl.xml:1052: The following error occurred while executing this line:
C:\Users\Carlos Vinicius\Documents\NetBeansProjects\JavaFXApplication2\nbproject\build-impl.xml:806: Java returned: 1
FALHA NA CONSTRUÇÃO (tempo total: 2 segundos)

============================================================================

Eis minha classe principal:

package javafxapplication2;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author Carlos Vinicius
 */
public class JavaFXApplication2 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(scene);
        stage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch();
    }

}

============================================================================== Eis meu fxml:

==============================================================================

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication2.FXMLDocumentController2">
   <children>
      <Button fx:id="btn" layoutX="248.0" layoutY="71.0" mnemonicParsing="false" text="Button" />
   </children>
</AnchorPane>

===============================================================================

Eis meu controller:

package javafxapplication2;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;

/**
 * FXML Controller class
 *
 * @author Carlos Vinicius
 */
public class FXMLDocumentController2 implements Initializable {

    /**
     * Initializes the controller class.
     */
    @FXML
    Button btn;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }    

}

============================================================================= Alguém saberia me dizer por que a aplicação não roda?

Versões(5):

Ver a versão formatada

Erro na execução de Aplicação JavaFX por FXML gerado pelo Scene Builder

Comentário

new question