Boa noite pessoal estou precisando de ajuda, sou novo em JavaFX e não estou conseguindo realizar um evento.
já comentei o evendo na classe e funciona normal ao descomentar o erro surgi novamente alguém me ajude ai.
minha classe main
`import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class PrimeiraView extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent parent = FXMLLoader.load(getClass().getResource("EstadoView.fxml"));
Scene scene = new Scene(parent);
stage.setScene(scene);
stage.setTitle("Cadastro de Estado");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
`
minha classe fxml
`<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
`
minha classe controle
`import java.net.URL;
import java.util.ResourceBundle;
import javax.swing.JOptionPane;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
public class EstadoController implements Initializable {
@FXML
private TextField txtEstado;
@FXML
private TextField txtSigla;
@FXML
private Button btSalvar, btEditar, btCancelar, btDeletar;
@Override
public void initialize(URL url, ResourceBundle bundle) {
btSalvar.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
JOptionPane.showInputDialog("Funcionando");
}
});
}
}`
Leom Cabral segue o erro.
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException:
/C:/Users/Mandrack/Documents/workspace/SisFrota/target/classes/br/com/sisfrota/visao/EstadoView.fxml
at javafx.fxml.FXMLLoader.constructLoadException(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 br.com.sisfrota.visao.PrimeiraView.start(PrimeiraView.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
... 1 more
Caused by: java.lang.NullPointerException
at br.com.sisfrota.visao.EstadoController.initialize(EstadoController.java:25)
… 18 more
Exception running application br.com.sisfrota.visao.PrimeiraView
Bom… Está parecendo que o arquivo da UI (EstadoView.fxml) não está sendo encontrado para ser carregado, ocasionando a exceção NullPointerException. Dê uma olhada se o caminho onde está o arquivo está correto.
Como não consegui ver quase nada do fxml vou ter que te perguntar:
Qual o fx:id no Button Salvar?
Ahhhh.
Meu nome é Leonardo.
obrigado consegui resolver.