I have de following Problem.
I have 2 FXML Controllers. 1. For Add Member 2. For Add Relation
Click on Add Relation Button from main program create instance od second controller.
After run program when I add New Member all works fine. When I click on Add Relation and next on button cancel or accept, and next I go to add new member and I do SUBMIT, the initialize method of second Controller is called. I dont understand why
@Override
public void initialize(URL url, ResourceBundle rb) {
log.trace(LogMessages.MSG_CTRL_INITIALIZATION);
this.languageBundle.setValue(rb);
relationType.setItems(FXCollections.observableArrayList(
RelationType.NEUTRAL,
RelationType.LOVE,
RelationType.FIANCE,
RelationType.MARRIED
));
/*
COMBOBOX CELL FACTORY
*/
setCellFactoryToCombobox(simLeftChoice);
setCellFactoryToCombobox(simRightChoice);
setCellFactoryToCombobox(childChoice);
setCellFactoryToRelationType(relationType);
toggleActiveButton.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue == true) {
toggleActiveButton.setText("Active");
} else {
toggleActiveButton.setText("Inactive");
}
});
toggleActiveButton.setSelected(true);
addLanguageListener();
addRegisterButtonDisableCondition();
/*
POPULATE COMBOBOX
*/
addSelectedMemberListener();
populateComboBox(context.getService().getCurrentFamily().getGtx_membersList().filtered(sexFilter(Sex.FEMALE)), simLeftChoice);
populateComboBox(context.getService().getCurrentFamily().getGtx_membersList().filtered(sexFilter(Sex.MALE)), simRightChoice);
populateComboBox(context.getService().getCurrentFamily().getGtx_membersList()
.filtered(p -> context.getService().getCurrentFamily().getBornRelation(p).isRacine()), childChoice);
simLeftChoice.getSelectionModel().selectFirst();
simRightChoice.getSelectionModel().selectFirst();
childChoice.getSelectionModel().selectFirst();
log.trace(LogMessages.MSG_CTRL_INITIALIZED);
}
I have an error in line :
populateComboBox(context.getService().getCurrentFamily().getGtx_membersList()
.filtered(p -> context.getService().getCurrentFamily().getBornRelation(p).isRacine()), childChoice);
Here is the stack trace :
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.genealogytree.client.desktop.controllers.implementation.TabAddNewRelationPaneController.lambda$initialize$2(TabAddNewRelationPaneController.java:143)
at javafx.collections.transformation.FilteredList.addRemove(FilteredList.java:268)
at javafx.collections.transformation.FilteredList.sourceChanged(FilteredList.java:144)
at javafx.collections.transformation.TransformationList.lambda$getListener$15(TransformationList.java:106)
at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
at javafx.collections.ModifiableObservableListBase.add(ModifiableObservableListBase.java:155)
at java.util.AbstractList.add(AbstractList.java:108)
at com.genealogytree.client.desktop.domain.GTX_Family.addMember(GTX_Family.java:55)
at com.genealogytree.client.desktop.service.implementation.LocalFamilyService.addMember(LocalFamilyService.java:71)
at com.genealogytree.client.desktop.controllers.implementation.TabAddNewMemberPaneController.addSimConfirm(TabAddNewMemberPaneController.java:131)
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.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
The problem is not this error but the fact that this fragment of code is called
The log :
14:53:30.453 TRACE .c.d.c.i.TabAddNewRelationPaneController : Controller Initialized correctly
14:53:31.730 TRACE .c.d.c.i.TabAddNewRelationPaneController : Finalize
14:53:33.758 TRACE .g.c.d.c.i.TabAddNewMemberPaneController : Initialization controller
14:53:33.760 TRACE .g.c.d.c.i.TabAddNewMemberPaneController : Controller Initialized correctly
14:53:39.075 INFO c.g.c.d.s.i.LocalFamilyService : Add new Member [GTX_Member{version=LongProperty [value: 0], id=LongProperty [value: 0], name=StringProperty [value: jiji], surname=StringProperty [value: ijij], photo=StringProperty [value: null], age=YOUNG_ADULT, sex=MALE}]
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
14:53:39.076 INFO c.g.c.d.s.i.LocalFamilyService : Add new Member [GTX_Member{version=LongProperty [value: 0], id=LongProperty [value: 2], name=StringProperty [value: jiji], surname=StringProperty [value: ijij], photo=StringProperty [value: null], age=YOUNG_ADULT, sex=MALE}]
at com.genealogytree.client.desktop.controllers.implementation.TabAddNewRelationPaneController.lambda$initialize$2(TabAddNewRelationPaneController.java:143)
I've been proceed some more test.
I changed a litle bit the code like this :
populateComboBox(context.getService().getCurrentFamily().getGtx_membersList().filtered(this::isRacine), childChoice);
public boolean isRacine(GTX_Member p) {
System.out.println("IS RACINE CALLED");
log.error("RACINE LAMBDA CALLED");
return context.getService().getCurrentFamily().getBornRelation(p).isRacine();
}
And now I was do debug 2 cases : a) breakpoint on line populate combobox b) breakpoint on predicate
As fabian mentionned the programm stopped at predicate only (breakpoint on line didn't cause the stop execution)
But I'm still don't understand why it is like this. At this moment this controller is not active. It seems there are an Listener on ObservableList of Member..
So, how can I remove this listener when calling Cancel method ?