Eu estou fazendo um programa javafx usando o Scene Builder. Bom, eu escrevi o código num editor de texto, passei para o NetBeans e executou normal, sem erro, mas quando eu tento executar pelo prompt de comando, dá erro.
Esse é o erro que aparece no prompt
Exception in Application start method java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473) at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:945) Caused by: java.lang.RuntimeException: Exception in Application start method at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973) at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198) at java.base/java.lang.Thread.run(Thread.java:844) Caused by: javafx.fxml.LoadException: /C:/Users/TI-DIRES/Desktop/Natalia/UESB/3º%20Semestre/Programação%20Concorrente/pc_trabalho01_201611579/telas/telaInicial.fxml:12 at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625) at javafx.fxml/javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:105) at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:930) at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980) at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227) at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752) at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3253) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3210) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3129) at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3122) at Principal.start(Principal.java:17) at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418) at java.base/java.security.AccessController.doPrivileged(Native Method) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417) at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96) at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175) ... 1 more Caused by: java.lang.ClassNotFoundException: controle.ControleTelaInicial at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496) at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:928) ... 22 more Exception running application Principal
Essa é a classe Principal
import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; import java.io.IOException; import javafx.scene.image.Image; public class Principal extends Application { public static void main (String[] args) { launch(args); } @Override public void start(Stage palco) throws IOException { FXMLLoader loader = new FXMLLoader(getClass().getResource("/telas/telaInicial.fxml")); loader.setController(this); Parent root = loader.load(); Scene cena = new Scene(root); palco.setScene(cena); palco.setTitle("Become Human: Gerador de Personagens"); palco.setResizable(true); palco.getIcons().add(new Image("/img/iconeBH.jpg")); palco.show(); } }
Esse aqui é o ControleTelaInicial
package controle; import java.net.URL; import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import java.io.IOException; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; public class ControleTelaInicial implements Initializable { @FXML private AnchorPane anchorBase; @FXML private AnchorPane anchorVariavel; @FXML private ImageView logo; @FXML void acessar(ActionEvent event) { try { FXMLLoader loader = new FXMLLoader(ControleTelaInicial.class.getResource("/telas/telaGerador.fxml")); AnchorPane anchorBase2 = loader.load(); ControleTelaGerador controle = loader.getController(); anchorBase.getChildren().clear(); anchorBase.getChildren().add(anchorBase2); } catch (IOException ex) { ex.printStackTrace(); } } @FXML void verInfo(ActionEvent event) { try { FXMLLoader loader = new FXMLLoader(ControleTelaInicial.class.getResource("/telas/telaInfo.fxml")); AnchorPane anchorBase2 = loader.load(); ControleTelaInfo controle = loader.getController(); anchorBase.getChildren().clear(); anchorBase.getChildren().add(anchorBase2); } catch (IOException ex) { ex.printStackTrace(); } } @Override public void initialize(URL location, ResourceBundle resources) { } }
E esse é o fxml da telaInicial
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.Cursor?> <?import javafx.scene.control.Button?> <?import javafx.scene.image.Image?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.HBox?> <?import javafx.scene.shape.Rectangle?> <?import javafx.scene.text.Font?> <AnchorPane fx:id="anchorBase" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" style="-fx-background-color: none;" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controle.ControleTelaInicial"> <children> <AnchorPane fx:id="anchorVariavel" prefHeight="600.0" prefWidth="800.0"> <children> <ImageView fx:id="logo" fitHeight="236.0" fitWidth="413.0" layoutX="226.0" layoutY="177.0" pickOnBounds="true" preserveRatio="true"> <image> <Image url="@../img/logoBH.jpg" /> </image> </ImageView> <Rectangle arcHeight="5.0" arcWidth="5.0" height="149.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="801.0" /> <Rectangle arcHeight="5.0" arcWidth="5.0" height="153.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="800.0" AnchorPane.topAnchor="448.0" /> <HBox layoutX="534.0" layoutY="447.0" spacing="10.0" AnchorPane.rightAnchor="42.0" AnchorPane.topAnchor="447.0"> <children> <Button fx:id="botaoAcessar" mnemonicParsing="false" onAction="#acessar" prefHeight="23.0" prefWidth="128.0" style="-fx-background-color: #fff;" text="ACESSAR"> <font> <Font name="Leelawadee Bold" size="12.0" /> </font> <cursor> <Cursor fx:constant="HAND" /> </cursor> </Button> <Button fx:id="botaoInfo" mnemonicParsing="false" onAction="#verInfo" prefHeight="25.0" prefWidth="87.0" style="-fx-background-color: #fff;" text="INFO"> <font> <Font name="Leelawadee Bold" size="12.0" /> </font> <cursor> <Cursor fx:constant="HAND" /> </cursor> </Button> </children> </HBox> </children> </AnchorPane> </children> </AnchorPane>