I'm trying to make an application for a college work using Maven, JavaFX, Persistence and Hibernate. I had a fully working code that used persistence, maven and hibernante with command line, and I just needed to make it work with a JavaFX interface (I couldn't find a Maven version that worked with the versions I had of Hibernate and Persistence, so I just manually added JavaFX instead of using Maven). For that, I followed a tutorial on JavaFX, and then I got myself a fully functioning but empty interface. So all I needed was to implement this interface into the Hibernate project. The problem is: Whenever I try to run my main application, I get the following error:
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:497) 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:497) 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$156(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalStateException: Location is not set. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at principal.Aplicacao.iniciarRootLayout(Aplicacao.java:72) at principal.Aplicacao.start(Aplicacao.java:51) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(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$149(WinApplication.java:191) ... 1 more Exception running application principal.Aplicacao
It seems like there is something work with my Start() method. The following is the code that is in the main app class (called "Aplicacao"):
package principal; import java.io.IOException; import java.util.List; import java.util.Scanner;
import dao.ProdutoDAO; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.BorderPane; import javafx.stage.Modality; import javafx.stage.Stage; import modelo.Produto; import view.ProdutoEditarDialogoControlador; import view.ProdutoVisaoGeralControlador;
public class Aplicacao extends Application { private Stage primaryStage; private BorderPane rootLayout; private ObservableList<Produto> produtoData = FXCollections.observableArrayList(); private static ProdutoDAO dao;
public Aplicacao() { }
public ObservableList<Produto> getProdutoData() { return produtoData; }
public static ProdutoDAO getDao() { return dao; }
@Override
public void start(Stage primaryStage){ this.primaryStage = primaryStage;
this.primaryStage.setTitle("Estoque de Produtos usando Hibernate e JavaFX");
this.primaryStage.getIcons().add(new Image("file:resources/images/iconfinder_Warehouse_32.png"));
iniciarRootLayout();
// dao = new ProdutoDAO();
// mostrarProdutoVisaoGeral();
// List<Produto> lista = dao.getTodos();
//for (int i = 0; i < (lista.size() - 1); i++) //{ // produtoData.add(new Produto(lista.get(i).getId(), lista.get(i).getNome())); //}
}
public void iniciarRootLayout() {
try
{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Aplicacao.class.getResource("view/RootLayout.fxml"));
rootLayout = (BorderPane) loader.load();
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
}
catch (IOException e)
{
e.printStackTrace();
} }
public void mostrarProdutoVisaoGeral() { try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Aplicacao.class.getResource("view/ProdutoVisaoGeral.fxml"));
AnchorPane produtoVisaoGeral = (AnchorPane) loader.load();
rootLayout.setCenter(produtoVisaoGeral);
ProdutoVisaoGeralControlador controller = loader.getController();
controller.setMainApp(this);
} catch (IOException e) {
e.printStackTrace(); } }
public Stage getPrimaryStage() { return primaryStage; }
public boolean mostrarProdutoDialogoEditar(Produto produto) {
try
{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Aplicacao.class.getResource("view/PersonEditDialog.fxml"));
AnchorPane page = (AnchorPane) loader.load();
Stage dialogStage = new Stage();
dialogStage.setTitle("Editar Produto");
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
ProdutoEditarDialogoControlador controller = loader.getController();
controller.setDialogStage(dialogStage);
controller.setProduto(produto);
dialogStage.showAndWait();
return controller.isOkClicked();
}
catch (IOException e)
{
e.printStackTrace();
return false;
} }
public static void main(String[] args) { launch(args); }