Bom dia, Criei uma aplicação javafx, mas quando tento passar de scene para o outro da-me este erro java.lang.reflect.InvocationTargetException na chamada do fxml.
Já pesquisei bastante mas nada resolve o problema.
MainApp
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gestorBiblioteca;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainApp extends Application {
public static ApplicationGPSD m_oApplication = new ApplicationGPSD();
@Override
public void start(Stage stage) throws IOException {
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("gestorBiblioteca/Menu.fxml"));
Scene scene = new Scene(root);
stage.setTitle("Gestor Biblioteca");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
MenuController
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gestorBiblioteca;
import java.io.IOException;
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 javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
/**
* FXML Controller class
*
* @author filip
*/
public class MenuController implements Initializable {
@FXML
private Button verLivros;
@FXML
private Button addLivros;
private MainApp application;
/**
* Initializes the controller class.
* @param url
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
// InicializarFicheiros initialize = new InicializarFicheiros();
// initialize.run();
}
public void setApp(MainApp application){
this.application = application;
}
public void gotoAddLivros(ActionEvent event) throws IOException {
Parent depositeView = FXMLLoader.load(getClass().getResource("gestorBiblioteca/AddLivros.fxml"));
Scene depositeViewScene = new Scene(depositeView);
Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
window.setScene(depositeViewScene);
window.show();
}
public void gotoVerLivros(ActionEvent event) throws IOException {
Parent depositeView = FXMLLoader.load(getClass().getResource("gestorBiblioteca/VerLivro.fxml"));
Scene depositeViewScene = new Scene(depositeView);
Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow();
window.setScene(depositeViewScene);
window.show();
}
}
AddLivrosController
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gestorBiblioteca;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXCheckBox;
import com.jfoenix.controls.JFXColorPicker;
import com.jfoenix.controls.JFXRadioButton;
import com.jfoenix.controls.JFXTextField;
import com.sun.javafx.css.converters.ColorConverter;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
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.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
/**
* FXML Controller class
*
* @author filip
*/
public class AddLivrosController implements Initializable {
private RegistarLivro m_lstLivros;
@FXML
private JFXTextField titulo;
@FXML
private JFXTextField autor;
@FXML
private JFXTextField ano;
@FXML
private Button voltar;
@FXML
private JFXButton addLivros;
@FXML
private Label areaText;
private Livros m_oLivro = MainApp.m_oApplication.getLivros();
private RegistarLivro m_oRegLivro = m_oLivro.getRegistoLivros();
@FXML
private JFXButton verLivros;
private MainApp application;
@FXML
private Button anima;
public void setApp(MainApp application){
this.application = application;
}
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
}
@FXML
public void gotoMenu(ActionEvent event) throws IOException{
Parent usertypes_page_parent = FXMLLoader.load(getClass().getResource("FXML.fxml"));
Scene usertypes_page_scene = new Scene(usertypes_page_parent);
Stage window2 = (Stage) ((Node)event.getSource()).getScene().getWindow();
window2.setScene(usertypes_page_scene);
window2.show();
}
@FXML
public void addLivro(ActionEvent Action)
{
if (ano.getText().isEmpty() || titulo.getText().isEmpty() || autor.getText().isEmpty()){
if (ano.getText().isEmpty()){
areaText.setText("Não se esqueça de preencher o ano");
areaText.setTextFill(Color.web("red"));
}
else if (titulo.getText().isEmpty()){
areaText.setText("Não se esqueça de colocar o titulo");
areaText.setTextFill(Color.web("red"));
}
else if (autor.getText().isEmpty()){
areaText.setText("Não se esqueça de preencher o autor");
areaText.setTextFill(Color.web("red"));
}
}
else {
String emp = "SIM";
Livros livro = m_oRegLivro.novoLivro(ano.getText(), titulo.getText(), autor.getText(), emp);
m_oRegLivro.registarLivro(livro);
areaText.setText("Livro adicionado com sucesso!");
areaText.setTextFill(Color.web("green"));
}
}
public void clearFields(){
ano.clear();
titulo.clear();
autor.clear();
}
public void verLivros(ActionEvent event) throws IOException{
Parent usertypes_page_parent = FXMLLoader.load(getClass().getResource("fxml/VerLivro.fxml"));
Scene usertypes_page_scene = new Scene(usertypes_page_parent);
Stage window2 = (Stage) ((Node)event.getSource()).getScene().getWindow();
window2.setScene(usertypes_page_scene);
window2.show();
}
}
Obrigado,


é comum em vez de falar toda vez “código-fonte” falar apenas fonte kk

