Problema para fazer o cast de duas scene JavaFX

0 respostas
programaçãojava
Noahlaster

Estou tentando criar duas telas com 1 botão em cada tela para sempre que clicar ele vai ficar trocando entre as telas, mas não estou conseguindo fazer o “cast” dessas telas.

package cadastro;

import javafx.application.Application;

import javafx.fxml.FXMLLoader;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.stage.Stage;

public class Main extends Application {

private static Stage stage;

private static Scene main;
private static Scene telacadastro;

@Override
public void start(Stage stage) throws Exception {
            
    Parent fxmlMain = FXMLLoader.load(getClass().getResource("../view/FXMLMain.fxml"));
    main = new Scene(fxmlMain, 640, 400);
    
    Parent fxmlTelaCadastro = FXMLLoader.load(getClass().getResource("../view/FXMLTelaCadastro.fxml"));
    telacadastro = new Scene(fxmlTelaCadastro, 640, 400);
    
    stage.setTitle("Primeira Tela");
    stage.setScene(main);
    stage.show();
}

public static void main(String[] args) {
    launch(args);
}

}

------------------------------------- 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: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:748)

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 cadastro.Main.start(Main.java:19)

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 cadastro.Main

Java Result: 1
Criado 12 de outubro de 2018
Respostas 0
Participantes 1