dimanche 30 novembre 2014

Can't get the list to put on my tableView. JavaFX and Hibernate


Vote count:

0




i'm having some trouble with getting the list of person from my db and put in the tableview, here is the code:


FuncionarioViewController:


private static ObservableList listaFuncionarios = FXCollections.observableArrayList(); private FuncionarioController funcionarioController; private SessionFactory sessionFactory; private MainApp mainApp;



@FXML
private TableView<Funcionario> tableFunc;
@FXML
private TableColumn<Funcionario, String> nomeColumn;
@FXML
private TableColumn<Funcionario, Number> cpfColumn;
@FXML
private TableColumn<Funcionario, String> cargoColumn;
@FXML
private Button deleteBtn;
@FXML
private Button editBtn;
@FXML
private TextField txPesquisa;


public FuncionarioViewController() {

}
@FXML
private void initialize() {
nomeColumn.setCellValueFactory(cellData -> cellData.getValue().nomeProperty());
cpfColumn.setCellValueFactory(cellData -> cellData.getValue().cpfProperty());
cargoColumn.setCellValueFactory(cellData -> cellData.getValue().cargoProperty());
tableFunc.getSelectionModel().selectedItemProperty().addListener(
(observable, oldValue,newValue)-> handleFuncionarioClicado(newValue));
}


public void addFunc() {
List<Funcionario> funcionarios = funcionarioController.findAllFuncionario();
listaFuncionarios.clear();
listaFuncionarios.addAll(funcionarios);
tableFunc.setItems(listaFuncionarios);
}

private void handleFuncionarioClicado(Funcionario func) {
if(func == null) {
deleteBtn.setDisable(true);
editBtn.setDisable(true);
} else {
deleteBtn.setDisable(false);
editBtn.setDisable(false);
}
}


the code of creating a query in db



public List<Funcionario> findAllFuncionario() {
try {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
List<Funcionario> funcionarios = session.createQuery("from funcionarios").list();
session.getTransaction().commit();
return funcionarios;

} catch (Exception e) {
e.printStackTrace();
return null;
}

}


mainApp class



public void showFunc() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("../view/Funcionarios.fxml"));
AnchorPane funcScreen = (AnchorPane) loader.load();
primaryStage.setTitle("EasySale - Funcionários");
rootLayout.setCenter(funcScreen);
FuncionarioViewController controller = loader.getController();
controller.setMainApp(this);
controller.setSessionFactory(sessionFactory);
controller.addFunc();

} catch (IOException e) {
e.printStackTrace();
}
}


And i'm getting these erros when i call showFunc()



Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.control.MenuItem.fire(Unknown Source)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(Unknown Source)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.lambda$createChildren$324(Unknown Source)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer$$Lambda$365/1130772527.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: 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 sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
... 44 more
Caused by: java.lang.NullPointerException
at easysale.view.FuncionarioViewController.addFunc(FuncionarioViewController.java:58)
at easysale.main.MainApp.showFunc(MainApp.java:240)
at easysale.view.RootLayoutController.showFunc(RootLayoutController.java:26)
... 53 more


Have no idea of what is the problem here.



asked 18 secs ago







Can't get the list to put on my tableView. JavaFX and Hibernate

Aucun commentaire:

Enregistrer un commentaire