NullPointerException - FXMLLoader.constructLoadException - javafx

I seem not to find a fitting solution to my problem.
I always get a NPE while loading the EntryView.fxml file.
I`ve already tried several path formats (e.g. relative, absolute).
Am I having a missconcept of how it works or is it a simple mistake?
All these files are in one package.
Here is the top part of the error log:
Mär 13, 2015 1:09:26 PM de.quest2go.authortool.entry.EntryController$1 handle
SCHWERWIEGEND: null
javafx.fxml.LoadException:
/Users/timzeidler/Uni/MCS/AuthortoolI/bin/de/quest2go/authortool/entry/EventEditView.fxml:9
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2595)
at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:918)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2701)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2521)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2435)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3208)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3169)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3142)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3118)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3098)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3091)
at de.quest2go.authortool.entry.EntryController$1.handle(EntryController.java:64)
at de.quest2go.authortool.entry.EntryController$1.handle(EntryController.java:1)
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.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:8216)
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.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:3724)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3452)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1728)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2461)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:348)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:273)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:382)
at com.sun.glass.ui.View.handleMouseEvent(View.java:553)
at com.sun.glass.ui.View.notifyMouse(View.java:925)
Caused by: java.lang.ClassNotFoundException: /EventEditController.java
The short FXML file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="EntryContoller.java">
<children>
<Button fx:id="eventBtn" layoutX="91.0" layoutY="319.0" mnemonicParsing="false" text="EventScene" />
<Button layoutX="270.0" layoutY="319.0" mnemonicParsing="false" text="ItemScene" />
<Button layoutX="457.0" layoutY="319.0" mnemonicParsing="false" text="EpisodeScene" />
</children>
</Pane>
And the Main:
public class EntryMain extends Application {
private Stage stage;
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
Application.launch(EntryMain.class, (java.lang.String[])null);
}
#Override
public void start(Stage primaryStage) {
try {
stage = primaryStage;
Parent root = FXMLLoader.load(getClass().getResource("EntryView.fxml"));
//VBox page = (VBox) FXMLLoader.load(EntryMain.class.getResource("EntryView.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Autorentool");
primaryStage.show();
} catch (Exception ex) {
Logger.getLogger(EntryMain.class.getName()).log(Level.SEVERE, null, ex);
}
}
And the controller with the FXMlLoader with the problem.
public class EntryController {
private Node node;
private Stage stage;
private Scene scene;
private FXMLLoader fxmlLoader;
private Parent root;
#FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
#FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
#FXML // fx:id="episodenEditorBtn"
private Button episodenEditorBtn; // Value injected by FXMLLoader
#FXML // fx:id="eventEditorBtn"
private Button eventEditorBtn; // Value injected by FXMLLoader
#FXML // fx:id="itemEditorBtn"
private Button itemEditorBtn; // Value injected by FXMLLoader
#FXML // This method is called by the FXMLLoader when initialization is complete
void initialize() {
assert episodenEditorBtn != null : "fx:id=\"episodenEditorBtn\" was not injected: check your FXML file 'EntryView.fxml'.";
assert eventEditorBtn != null : "fx:id=\"eventEditorBtn\" was not injected: check your FXML file 'EntryView.fxml'.";
assert itemEditorBtn != null : "fx:id=\"itemEditorBtn\" was not injected: check your FXML file 'EntryView.fxml'.";
eventEditorBtn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
try {
stage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("EventEditView.fxml"));
//VBox page = (VBox) FXMLLoader.load(EntryMain.class.getResource("EntryView.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Autorentool");
stage.show();
} catch (Exception ex) {
Logger.getLogger(EntryMain.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
Thanks in advance for helping me.

Related

Switching FXML Scene Builder files [duplicate]

This question already has answers here:
What's the difference between fx:id and id: in JavaFX?
(4 answers)
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 2 years ago.
I have a problem switching from 1 fxml file into another (created in Scene Builder 2.0) and everything I find on internet says the same, but the code just doesnt work for me, any help will be highly appreciated:
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.Button;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
/**
* FXML Controller class
*
* u/author andys
*/
public class ScenestartController implements Initializable {
u/FXML
private AnchorPane paneone;
u/FXML
Button manualbutton;
u/FXML
Button simbutt;
/**
* Initializes the controller class.
*/
u/Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
System.out.println("Loaded");
}
u/FXML
private void handlemanualbutton(ActionEvent event) throws Exception {
Parent rooter = FXMLLoader.load(getClass().getResource("/fxml/drawbridgefirst.fxml"));
Scene sceno = new Scene(rooter);
Stage stago = (Stage)((Node)event.getSource()).getScene().getWindow();
stago.setTitle("Manual");
stago.setScene(sceno);
stago.show();
}
u/FXML
private void handleSimButt(ActionEvent event) throws Exception {
Parent rooters = FXMLLoader.load(getClass().getResource("/fxml/drawbridgefirst.fxml"));
Scene scenos = new Scene(rooters);
Stage stagos = (Stage)((Node)event.getSource()).getScene().getWindow();
stagos.setTitle("simulation");
stagos.setScene(scenos);
stagos.show();
}}
This is a start scene that loads from main, but when I press the manualbutton or simbutt button (to switch to one of the other fxml files) I get this error:
WARNING: Loading FXML document with JavaFX API of version 11.0.1 by JavaFX `runtime of version 8.0.231 Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
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.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:8411)
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.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:394)
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$2(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
at java.lang.Thread.run(Thread.java:748) Caused by: 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: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:1769) ... 48 more Caused by: javafx.fxml.LoadException: /C:/Users/andys/Documents/Fontys/Semester3/prj3-repair/repair-rudystylz/Project3Repf/target/classes/fxml/drawbridgefirst.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at ScenestartController.handlemanualbutton(ScenestartController.java:60) ... 58 more Caused by: java.lang.NullPointerException
at DrawbridgefirstController.initialize(DrawbridgefirstController.java:32)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) ... 66 more
The DrawbridgefirstController:
/*
* 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.
*/
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
/**
* FXML Controller class
*
* #author andys
*/
public class DrawbridgefirstController implements Initializable {
#FXML
public TextField texta;
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
texta.setText("Boat approached and pressed the button");
}
#FXML
public void upbuttclick(ActionEvent actionEvent) {
texta.setText("Bridge is going up!");
}
#FXML
public void downbuttclick(ActionEvent actionEvent) {
texta.setText("Bridge is going down!");
}
#FXML
public void maintbuttclick(ActionEvent actionEvent) {
texta.setText("Bridge is in maintenance!");
}
}
drawbridgefirst.fxml code:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="panetu" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="DrawbridgefirstController">
<children>
<Button id="upbutton" layoutX="509.0" layoutY="51.0" mnemonicParsing="false" onAction="#upbuttclick" text="Up" />
<Button id="downbutton" layoutX="501.0" layoutY="107.0" mnemonicParsing="false" onAction="#downbuttclick" text="Down" />
<Button id="maintenance" layoutX="482.0" layoutY="159.0" mnemonicParsing="false" onAction="#maintbuttclick" text="Maintenance" />
<TextField id="texta" layoutX="46.0" layoutY="261.0" prefHeight="104.0" prefWidth="407.0" />
</children>
</AnchorPane>

show TableView data into another Window contains TextField in JavaFx

I have made Two Fxml file one contains TextField and another contains TableView. And it has its Controller class. I want to show data from TableView to TextField when mouse clicked action event is performed. But we didn't get the result it shows a lots of error like :
Jun 02, 2018 8:33:36 AM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX runtime of version 8.0.162
Jun 02, 2018 8:33:44 AM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
INFO: Could not find stylesheet: file:/C:/Users/MdAzaz/IdeaProjects/JavaFxProject3/out/production/Stylesheet/style.css
Jun 02, 2018 8:33:46 AM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX runtime of version 8.0.162
Jun 02, 2018 8:33:50 AM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX runtime of version 8.0.162
java.lang.NullPointerException
at Company.CompanyTableController.Clicked(CompanyTableController.java:123)
at Company.CompanyTableController.access$100(CompanyTableController.java:35)
at Company.CompanyTableController$2.handle(CompanyTableController.java:108)
at Company.CompanyTableController$2.handle(CompanyTableController.java:105)
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:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470)
at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3766)
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:394)
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$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
Process finished with exit code 0
The first Fxml file name CompanyLayout.fxml contains TextFields and it has its Controller class like CompanyController.java. It has Button name Find when i clicked on that button CompanyTable.fxml is opened which contain TableView. When i clicked on perticular row of TableView the data of that row will display on CompanyLayout.fxml which contains Textfields.
Find Button code for CompanyController.java is this:
btnFind.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
try {
Stage primaryStage = new Stage();
FXMLLoader loader = new FXMLLoader();
Parent root = loader.load(getClass().getClassLoader().getResource("Company\\CompanyTable.fxml"));
Scene scene=new Scene(root);
scene.getStylesheets().add(getClass().getClassLoader().getResource("Stylesheet\\style.css").toExternalForm());
primaryStage.setTitle("Company Table");
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
TableView Code for CompanyTableController.java is this:
CompanyTable.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
Clicked();
}
});
private void Clicked()
{
try
{
CompanyData categoryData=CompanyTable.getItems().get(CompanyTable.getSelectionModel().getSelectedIndex());
CategoryID.setText(categoryData.getCompanyID());
CategoryName.setText(categoryData.getCompanyName());
}
catch(Exception e)
{
e.printStackTrace();
}
}
I hope you will understand this code so, please help me!
I created a sample app that demos your question.
The key is passing data from one Controller to another. You can find info here.
Here is the key code:
#FXML
private void handleButtonAction(ActionEvent event) {
try
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("SearchPanel.fxml"));
Parent root = loader.load();
SearchPanelController searchPanelController = loader.getController();//Get access to the Controller
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.showAndWait();//Wait for the Search Controller to close.
Customer tempCustomer = searchPanelController.getCustomer();//Get the selected customer from the Search Controller. HAVE A LOOK AT THE SearchPanelController!
//Set the selected customer to the TextFields
tfFirstName.setText(tempCustomer.getFirstName());
tfLastName.setText(tempCustomer.getLastName());
tfEmail.setText(tempCustomer.getEmail());
} catch (IOException e)
{
e.printStackTrace();
}
}
Full App - Main Class:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
*
* #author sedri
*/
public class JavaFXApplication3 extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Customer Class:
/**
*
* #author sedrick
*/
public class Customer {
private String firstName;
private String lastName;
private String email;
public Customer(String firstName, String lastName, String email) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
/**
* #return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* #param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* #return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* #param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* #return the email
*/
public String getEmail() {
return email;
}
/**
* #param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
}
FXMLDocumentController Class:
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.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
/**
*
* #author sedri
*/
public class FXMLDocumentController implements Initializable {
#FXML TextField tfFirstName, tfLastName, tfEmail;
#FXML
private void handleButtonAction(ActionEvent event) {
try
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("SearchPanel.fxml"));
Parent root = loader.load();
SearchPanelController searchPanelController = loader.getController();
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.showAndWait();
Customer tempCustomer = searchPanelController.getCustomer();
tfFirstName.setText(tempCustomer.getFirstName());
tfLastName.setText(tempCustomer.getLastName());
tfEmail.setText(tempCustomer.getEmail());
} catch (IOException e)
{
e.printStackTrace();
}
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
FXMLDocument FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="484.0" prefWidth="667.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication3.FXMLDocumentController">
<children>
<MenuBar>
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<StackPane prefHeight="150.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<children>
<VBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity">
<children>
<HBox maxHeight="-Infinity" maxWidth="-Infinity">
<children>
<Label maxHeight="1.7976931348623157E308" text="First Name:" />
<TextField fx:id="tfFirstName" />
</children>
</HBox>
<HBox maxHeight="-Infinity" maxWidth="-Infinity">
<children>
<Label maxHeight="1.7976931348623157E308" maxWidth="-Infinity" prefWidth="60.0" text="Last Name:" />
<TextField fx:id="tfLastName" />
</children>
</HBox>
<HBox maxHeight="-Infinity" maxWidth="-Infinity">
<children>
<Label alignment="CENTER_RIGHT" maxHeight="1.7976931348623157E308" prefWidth="60.0" text="Email: " />
<TextField fx:id="tfEmail" />
</children>
</HBox>
<Button alignment="CENTER" mnemonicParsing="false" onAction="#handleButtonAction" text="Search" />
</children>
</VBox>
</children>
</StackPane>
</children>
</VBox>
SearchPanelController Class:
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
/**
* FXML Controller class
*
* #author sedri
*/
public class SearchPanelController implements Initializable {
#FXML TableView<Customer> tvSearch;
#FXML TableColumn tcFirstName, tcLastName, tcEmail;
Customer selectedCustomer;
/**
* Initializes the controller class.
* #param url
* #param rb
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
tvSearch.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection)->{
if(newSelection != null)
{
selectedCustomer = newSelection;
tvSearch.getScene().getWindow().hide();
}
});
tcFirstName.setCellValueFactory(new PropertyValueFactory("firstName"));
tcLastName.setCellValueFactory(new PropertyValueFactory("lastName"));
tcEmail.setCellValueFactory(new PropertyValueFactory("email"));
ObservableList<Customer> data =
FXCollections.observableArrayList(
new Customer("Jacob", "Smith", "jacob.smith#example.com"),
new Customer("Isabella", "Johnson", "isabella.johnson#example.com"),
new Customer("Ethan", "Williams", "ethan.williams#example.com"),
new Customer("Emma", "Jones", "emma.jones#example.com"),
new Customer("Michael", "Brown", "michael.brown#example.com")
);
tvSearch.setItems(data);
}
public Customer getCustomer()
{
return selectedCustomer;
}
}
SearchPanel FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication3.SearchPanelController">
<children>
<TableView fx:id="tvSearch" prefHeight="200.0" prefWidth="200.0">
<columns>
<TableColumn fx:id="tcFirstName" prefWidth="153.0" text="First Name" />
<TableColumn fx:id="tcLastName" prefWidth="182.0" text="Last Name" />
<TableColumn fx:id="tcEmail" prefWidth="263.0" text="Email" />
</columns>
</TableView>
</children>
</StackPane>

NullPointerException when calling method with (JavaFX)

When I call the login method in the LoginViewController class I receive a NullPointerException. I know that the user object is not null since it prints out the object with a toString. Do I have to register the Client and User class in the LoginView.fxml in some way? What Im trying to achieve is that when the user clicks on login the method should instantiate a new Client which sends the User object to the server.
Exception
User: Username Password
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
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.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:8411)
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.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:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
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)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 48 more
Caused by: java.lang.NullPointerException
at dinnerTime.Client.sendToServer(Client.java:44)
at dinnerTime.LoginViewController.login(LoginViewController.java:34)
... 58 more
Main.java
package dinnerTime;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
private Stage primaryStage;
private BorderPane mainLayout;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;
showLoginView();
}
private void showLoginView() throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("LoginView.fxml"));
mainLayout = loader.load();
Scene scene = new Scene(mainLayout, 540, 400);
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.show();
}
}
LoginViewController.java
package dinnerTime;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
public class LoginViewController {
#FXML
private Main main;
#FXML
private TextField username;
#FXML
private PasswordField password;
#FXML
private Button login;
#FXML
private Button register;
private Client client;
private User user;
#FXML
public void login() throws IOException {
client = new Client("127.0.0.1", 3250);
client.start();
user = new User(username.getText(), password.getText());
System.out.println("User: " + user.toString());
client.sendToServer(user);
}
}
LoginView.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.Font?>
<BorderPane prefHeight="400.0" prefWidth="540.0" xmlns="http://javafx.com/javafx/8.0.102" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dinnerTime.LoginViewController">
<center>
<AnchorPane prefHeight="400.0" prefWidth="540.0" BorderPane.alignment="CENTER">
<children>
<ImageView fitHeight="122.0" fitWidth="124.0" layoutX="238.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../../images/dt-logo-original.png" />
</image>
</ImageView>
<Label layoutX="14.0" layoutY="14.0" text="Dinner" textFill="#464646">
<font>
<Font size="70.0" />
</font>
</Label>
<Label layoutX="372.0" layoutY="14.0" text="Time" textFill="#464646">
<font>
<Font size="70.0" />
</font></Label>
<Label layoutX="91.0" layoutY="155.0" text="Username" />
<TextField layoutX="164.0" layoutY="151.0" prefHeight="25.0" prefWidth="216.0" />
<Label layoutX="91.0" layoutY="213.0" text="Password" />
<PasswordField layoutX="164.0" layoutY="209.0" prefHeight="25.0" prefWidth="216.0" />
<Button fx:id="login" layoutX="162.0" layoutY="271.0" mnemonicParsing="false" onAction="#login" prefHeight="59.0" prefWidth="216.0" text="Login" />
<Button layoutX="242.0" layoutY="352.0" mnemonicParsing="false" text="Register" />
</children>
</AnchorPane>
</center>
</BorderPane>
Client.java
package dinnerTime;
import java.io.*;
import java.net.*;
public class Client extends Thread {
private String ip;
private int port;
private Socket socket;
private ObjectOutputStream oos;
private ObjectInputStream ois;
public Client(String ip, int port) {
this.ip = ip;
this.port = port;
}
public void run() {
try {
socket = new Socket(ip, port);
oos = new ObjectOutputStream(socket.getOutputStream());
oos.flush();
ois = new ObjectInputStream(socket.getInputStream());
while (true) {
try {
Object obj = ois.readObject();
if (obj instanceof Recipe) {
}
} catch (IOException | ClassNotFoundException e) {
}
}
} catch (IOException e) {
}
}
public void sendToServer(Object obj) {
try {
oos.writeObject(obj);
oos.flush();
} catch (IOException e) {
}
}
}
User.java
package dinnerTime;
import java.io.Serializable;
public class User implements Serializable {
private String name, password;
public User(String name, String password){
this.name = name;
this.password = password;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString() {
return name + " " + password;
}
}
You have a race condition on the client's oos field. You initialize it in the run() method, which is executed on the background thread, but you try to access it in sendToServer() which is called from login() in the controller, and executed on the FX Application Thread.
Because these are on different threads, there is no guarantee as to which will be executed first: what is happening is that sendToServer() is getting executed before the background thread initializes oos, and hence oos.writeObject(...) is throwing a null pointer exception.
To fix this, you need to ensure that you do not call sendToServer() until the client is fully connected. One approach is to provide a callback of some kind to execute when the connection is established:
public class Client extends Thread {
private String ip;
private int port;
private Socket socket;
private ObjectOutputStream oos;
private ObjectInputStream ois;
private Runnable onConnected ;
public void setOnConnected(Runnable onConnected) {
this.onConnected = onConnected ;
}
public Client(String ip, int port) {
this.ip = ip;
this.port = port;
}
public void run() {
try {
socket = new Socket(ip, port);
oos = new ObjectOutputStream(socket.getOutputStream());
oos.flush();
if (onConnected != null) {
onConnected.run();
}
ois = new ObjectInputStream(socket.getInputStream());
while (true) {
try {
Object obj = ois.readObject();
if (obj instanceof Recipe) {
}
} catch (IOException | ClassNotFoundException e) {
}
}
} catch (IOException e) {
}
}
public void sendToServer(Object obj) {
try {
oos.writeObject(obj);
oos.flush();
} catch (IOException e) {
}
}
}
and then
#FXML
public void login() throws IOException {
client = new Client("127.0.0.1", 3250);
user = new User(username.getText(), password.getText());
client.setOnConnected(() -> client.sendToServer(user));
client.start();
}

Not allowing me to do each action more than once

I am having an issue with my code where whenever I try to do something more than once, the program will crash on me. For example, if I login, then log out and then log back in for a second time, the program will crash. This is happening for other things that I want to do more than once such as switching to another scene, going back to home then trying to go to the other scene again.
Will just post the code for the login part.
Main
package libraryapp;
import java.io.File;
import java.io.IOException;
import java.util.prefs.Preferences;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import libraryapp.model.Book;
import libraryapp.model.BookListWrapper;
import libraryapp.view.BrowseController;
import libraryapp.view.HomeOverviewController;
import libraryapp.view.LoginController;
import libraryapp.view.RootLayoutController;
public class LibraryApp extends Application {
private Stage primaryStage;
private BorderPane rootLayout;
/**
* The data as an observable list of Books.
*/
private ObservableList<Book> bookData = FXCollections.observableArrayList();
/**
* Constructor
*/
public LibraryApp() {
// Add some sample data
bookData.add(new Book("Hans", "Muster"));
bookData.add(new Book("Ruth", "Mueller"));
bookData.add(new Book("Heinz", "Kurz"));
bookData.add(new Book("Cornelia", "Meier"));
bookData.add(new Book("Werner", "Meyer"));
bookData.add(new Book("Lydia", "Kunz"));
bookData.add(new Book("Anna", "Best"));
bookData.add(new Book("Stefan", "Meier"));
bookData.add(new Book("Martin", "Mueller"));
}
/**
* Returns the data as an observable list of Books.
* #return
*/
public ObservableList<Book> getBookData() {
return bookData;
}
#Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("LibraryApp");
initRootLayout();
showLogin();
}
/**
* Initializes the root layout and tries to load the last opened
* person file.
*/
public void initRootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(LibraryApp.class.getResource("view/RootLayout.fxml"));
rootLayout = (BorderPane) loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
// Give the controller access to the main app.
RootLayoutController controller = loader.getController();
controller.setLibraryApp(this);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
// Try to load last opened person file.
File file = getBookFilePath();
if (file != null) {
loadBookDataFromFile(file);
}
}
/**
* Shows the home overview inside the root layout.
*/
public void showHomeOverview() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(LibraryApp.class.getResource("view/HomeOverview.fxml"));
AnchorPane homeOverview = (AnchorPane) loader.load();
// Set home overview into the center of root layout.
rootLayout.setCenter(homeOverview);
// Give the controller access to the main app.
HomeOverviewController controller = loader.getController();
controller.setLibraryApp(this);
} catch (IOException e) {
e.printStackTrace();
}
}
public void showLogin() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(LibraryApp.class.getResource("view/Login.fxml"));
AnchorPane login = (AnchorPane) loader.load();
// Set home overview into the center of root layout.
rootLayout.setCenter(login);
// Give the controller access to the main app.
LoginController controller = loader.getController();
controller.setLibraryApp(this);
} catch (IOException e) {
e.printStackTrace();
}
}
public void showBrowse() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(LibraryApp.class.getResource("view/Browse.fxml"));
AnchorPane browse = (AnchorPane) loader.load();
// Set browse into the center of root layout.
rootLayout.setCenter(browse);
// Give the controller access to the main app.
BrowseController controller = loader.getController();
controller.setLibraryApp(this);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Returns the main stage.
* #return
*/
public Stage getPrimaryStage() {
return primaryStage;
}
public static void main(String[] args) {
Application.launch(args);
}
Login Controller
package libraryapp.view;
import java.io.File;
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.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import libraryapp.LibraryApp;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
* FXML Controller class
*
* #author Michael
*/
public class LoginController implements Initializable {
/**
* Initializes the controller class.
*/
#FXML
private AnchorPane loginPane;
#FXML
private Label lblMessage;
#FXML
private TextField txtUsername;
#FXML
private PasswordField txtPassword;
private LibraryApp libraryApp;
public String getString(String tagName) throws SAXException, IOException, ParserConfigurationException{
File file = new File("src/libraryapp/account.xml");
DocumentBuilderFactory docBuildFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuildFactory.newDocumentBuilder();
Document document = docBuilder.parse(file);
NodeList list = document.getElementsByTagName(tagName);
if (list != null && list.getLength() > 0){
NodeList subList = list.item(0).getChildNodes();
if (subList != null && subList.getLength() > 0) {
return subList.item(0).getNodeValue();
}
}
return null;
}
#FXML
private void login(ActionEvent event) throws IOException, ParserConfigurationException, SAXException {
String email = getString("email");
String password = getString("password");
if (txtUsername.getText().equals(email) && txtPassword.getText().equals(password)){
libraryApp.showHomeOverview();
} else{
lblMessage.setText("Username or password invalid!");
}
}
#FXML
private void register(ActionEvent event) throws IOException {
AnchorPane pane = FXMLLoader.load(getClass().getResource("Register.fxml"));
loginPane.getChildren().setAll(pane);
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
public void setLibraryApp(LibraryApp libraryApp) {
this.libraryApp = libraryApp;
}
}
And this is the error that I get
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
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.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.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)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: 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: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:1769)
... 52 more
Caused by: java.lang.NullPointerException
at libraryapp.view.LoginController.login(LoginController.java:82)
... 62 more
Logout
#FXML
public void logout(ActionEvent event) throws IOException {
File bookFile = libraryApp.getBookFilePath();
libraryApp.saveBookDataToFile(bookFile);
AnchorPane pane = FXMLLoader.load(getClass().getResource("Login.fxml"));
browsePane.getChildren().setAll(pane);
}
Your implementation of logout() loads the login fxml file again, but does not set the libraryApp field on the new controller. Consequently, that field is null in that instance of the controller, and you get a null pointer exception.
Since you already have a reference to the libraryApp, you can reuse the existing code to load the login screen simply by calling
libraryApp.showLogin();

JavaFX tableview to be populated from CSV

I'm new to JavaFX and I'm just trying to populate a tableview defined in FXML from a CSV text file. My code is as follows:
package student;
import java.net.URL;
import java.util.*;
import javafx.fxml.*;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
public class StudInfoController implements Initializable {
#FXML
private Tab profile;
#FXML
private Label namelbl;
#FXML
private Label clslbl;
#FXML
private Label divlbl;
#FXML
private Label rnolbl;
#FXML
private Label maillbl;
#FXML
private Label moblbl;
#FXML
private Label altlbl;
#FXML
private Tab exams;
#FXML
private Tab result;
#FXML
private TableView<Exam> ExamTable;
#FXML
private TableView<Result> ResultTable;
#FXML
private TableColumn<Exam, String> eSub;
#FXML
private TableColumn<Exam, String> eDate;
#FXML
private TableColumn<Exam, String> eDur;
#FXML
private TableColumn<Exam, String> eMarks;
#FXML
private TableColumn<Result, String> rSub;
#FXML
private TableColumn<Result, String> rDate;
#FXML
private TableColumn<Result, String> rTT;
#FXML
private TableColumn<Result, String> rTE;
#FXML
private TableColumn<Result, String> rMarks;
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
eSub.setCellValueFactory(new PropertyValueFactory<>("eSub"));
eDate.setCellValueFactory(new PropertyValueFactory<>("eDate"));
eDur.setCellValueFactory(new PropertyValueFactory<>("eDur"));
eMarks.setCellValueFactory(new PropertyValueFactory<>("eMarks"));
rSub.setCellValueFactory(new PropertyValueFactory<>("rSub"));
rDate.setCellValueFactory(new PropertyValueFactory<>("rDate"));
rTT.setCellValueFactory(new PropertyValueFactory<>("rTT"));
rTE.setCellValueFactory(new PropertyValueFactory<>("rTE"));
rMarks.setCellValueFactory(new PropertyValueFactory<>("rMarks"));
ExamTable.getItems().setAll(InsertExam());
ResultTable.getItems().setAll(InsertResult());
}
private List<Exam> InsertExam() {
try {
FileRead fr = new FileRead();
String[] l = fr.examRead();
String[] items;
int i = 0;
Exam r = new Exam();
List<Exam> row = new ArrayList<>();
for (i = 0; i < l.length; i++) {
items = l[i].split(",");
r.setESub(items[0]);
r.setEDate(items[1]);
r.setEDur(items[2]);
r.setEMarks(items[3]);
row.add(r);
}
return row;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private List<Result> InsertResult() {
try {
FileRead fr = new FileRead();
String[] l = fr.resultRead();
String[] items;
Result r = new Result();
List<Result> row = new ArrayList<>();
for (int i = 0; i < l.length; i++) {
items = l[i].split(",");
r.setRSub(items[0]);
r.setRDate(items[1]);
r.setRTT(items[2]);
r.setRTE(items[3]);
r.setRMarks(items[4]);
row.add(r);
}
return row;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
class Exam {
private String eSub;
private String eDate;
private String eDur;
private String eMarks;
public Exam() {
}
public String getESub() {
return eSub;
}
public void setESub(String eSub) {
this.eSub = eSub;
}
public String getEDate() {
return eDate;
}
public void setEDate(String eDate) {
this.eDate = eDate;
}
public String getEDur() {
return eDur;
}
public void setEDur(String eDur) {
this.eDur = eDur;
}
public String getEMarks() {
return eMarks;
}
public void setEMarks(String eMarks) {
this.eMarks = eMarks;
}
}
class Result {
private String rSub;
private String rDate;
private String rTT;
private String rTE;
private String rMarks;
public String getRSub() {
return rSub;
}
public void setRSub(String rSub) {
this.rSub = rSub;
}
public String getRDate() {
return rDate;
}
public void setRDate(String rDate) {
this.rDate = rDate;
}
public String getRTT() {
return rTT;
}
public void setRTT(String rTT) {
this.rTT = rTT;
}
public String getRTE() {
return rTE;
}
public void setRTE(String rTE) {
this.rTE = rTE;
}
public String getRMarks() {
return rMarks;
}
public void setRMarks(String rMarks) {
this.rMarks = rMarks;
}
public Result() {
}
}
}
The FXML code is as follows:
<TableView fx:id="ResultTable" prefHeight="345.0" prefWidth="697.0">
<columns>
<TableColumn fx:id="rSub" editable="false" prefWidth="297.0"
text="SUBJECT"/>
<TableColumn fx:id="rDate" editable="false" prefWidth="97.0"
text="DATE" />
<TableColumn fx:id="rTT" editable="false" prefWidth="123.0"
text="TOTAL TIME"/>
<TableColumn fx:id="rTE" editable="false" prefWidth="116.0"
text="TIME ELAPSED" />
<TableColumn fx:id="rMarks" editable="false" prefWidth="63.0"
text="MARKS" />
</columns>
</TableView>
<TableView fx:id="ExamTable" prefHeight="344.0" prefWidth="697.0">
<columns>
<TableColumn fx:id="eSub" editable="false" prefWidth="414.0"
text="SUBJECT" />
<TableColumn fx:id="eDate" editable="false" prefWidth="148.0"
text="DATE" />
<TableColumn fx:id="eDur" editable="false" prefWidth="79.0"
text="DURATION" />
<TableColumn fx:id="eMarks" editable="false" prefWidth="55.0"
text="MARKS" />
</columns>
</TableView>
The following exception is being thrown:
Executing C:\Users\ANIL\Documents\NetBeansProjects\Student\dist\run775021387\Student.jar using platform C:\Program Files\Java\jdk1.8.0_111\jre/bin/java
java.lang.RuntimeException: java.lang.IllegalAccessException: Class sun.reflect.misc.Trampoline can not access a member of class student.StudInfoController$Result with modifiers "public"
at com.sun.javafx.property.PropertyReference.get(PropertyReference.java:177)
at javafx.scene.control.cell.PropertyValueFactory.getCellDataReflectively(PropertyValueFactory.java:147)
at javafx.scene.control.cell.PropertyValueFactory.call(PropertyValueFactory.java:119)
at javafx.scene.control.cell.PropertyValueFactory.call(PropertyValueFactory.java:98)
at javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:578)
at javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:563)
at javafx.scene.control.TableCell.updateItem(TableCell.java:644)
at javafx.scene.control.TableCell.indexChanged(TableCell.java:468)
at javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:116)
at com.sun.javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:533)
at com.sun.javafx.scene.control.skin.TableRowSkinBase.init(TableRowSkinBase.java:147)
at com.sun.javafx.scene.control.skin.TableRowSkin.<init>(TableRowSkin.java:64)
at javafx.scene.control.TableRow.createDefaultSkin(TableRow.java:212)
at javafx.scene.control.Control.impl_processCSS(Control.java:872)
at javafx.scene.Node.processCSS(Node.java:9058)
at javafx.scene.Node.applyCss(Node.java:9155)
at com.sun.javafx.scene.control.skin.VirtualFlow.setCellIndex(VirtualFlow.java:1964)
at com.sun.javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1797)
at com.sun.javafx.scene.control.skin.VirtualFlow.getCellLength(VirtualFlow.java:1879)
at com.sun.javafx.scene.control.skin.VirtualFlow.computeViewportOffset(VirtualFlow.java:2528)
at com.sun.javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:1189)
at javafx.scene.Parent.layout(Parent.java:1087)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Scene.doLayoutPass(Scene.java:552)
at javafx.scene.Scene.preferredSize(Scene.java:1646)
at javafx.scene.Scene.impl_preferredSize(Scene.java:1720)
at javafx.stage.Window$9.invalidated(Window.java:846)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:144)
at javafx.stage.Window.setShowing(Window.java:922)
at javafx.stage.Window.show(Window.java:937)
at javafx.stage.Stage.show(Stage.java:259)
at student.StudentFXMLController.OKBtnAction(StudentFXMLController.java:65)
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:1769)
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.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.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:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalAccessException: Class sun.reflect.misc.Trampoline can not access a member of class student.StudInfoController$Result with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
at java.lang.reflect.Method.invoke(Method.java:491)
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 com.sun.javafx.property.PropertyReference.get(PropertyReference.java:175)
... 94 more
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.IllegalAccessException: Class sun.reflect.misc.Trampoline can not access a member of class student.StudInfoController$Result with modifiers "public"
at com.sun.javafx.property.PropertyReference.get(PropertyReference.java:177)
at javafx.scene.control.cell.PropertyValueFactory.getCellDataReflectively(PropertyValueFactory.java:147)
at javafx.scene.control.cell.PropertyValueFactory.call(PropertyValueFactory.java:119)
at javafx.scene.control.cell.PropertyValueFactory.call(PropertyValueFactory.java:98)
at javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:578)
at javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:563)
at javafx.scene.control.TableCell.updateItem(TableCell.java:644)
at javafx.scene.control.TableCell.indexChanged(TableCell.java:468)
at javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:116)
at com.sun.javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:533)
at com.sun.javafx.scene.control.skin.TableRowSkinBase.init(TableRowSkinBase.java:147)
at com.sun.javafx.scene.control.skin.TableRowSkin.<init>(TableRowSkin.java:64)
at javafx.scene.control.TableRow.createDefaultSkin(TableRow.java:212)
at javafx.scene.control.Control.impl_processCSS(Control.java:872)
at javafx.scene.Parent.impl_processCSS(Parent.java:1280)
at javafx.scene.Parent.impl_processCSS(Parent.java:1280)
at javafx.scene.Parent.impl_processCSS(Parent.java:1280)
at javafx.scene.control.Control.impl_processCSS(Control.java:868)
at javafx.scene.Parent.impl_processCSS(Parent.java:1280)
at javafx.scene.Parent.impl_processCSS(Parent.java:1280)
at javafx.scene.Parent.impl_processCSS(Parent.java:1280)
at javafx.scene.control.Control.impl_processCSS(Control.java:868)
at javafx.scene.Node.processCSS(Node.java:9058)
at javafx.scene.Node.processCSS(Node.java:9051)
at javafx.scene.Scene.doCSSPass(Scene.java:545)
at javafx.scene.Scene.access$3600(Scene.java:159)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2392)
at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:354)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:381)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:510)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
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$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalAccessException: Class sun.reflect.misc.Trampoline can not access a member of class student.StudInfoController$Result with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
at java.lang.reflect.Method.invoke(Method.java:491)
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 com.sun.javafx.property.PropertyReference.get(PropertyReference.java:175)
... 37 more
Well the issue was with the class declaration. the class has to be public. And the issue is resolved. thanks for the help

Resources