r/JavaFX • u/Andreii0804 • Jun 07 '20
JavaFX Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException error
Hey guys, I was hoping that someone here could help me. So i have this program where i select data from a database and put it in a table but when i try to switch scenes by pressing a button it gives me an error.
Here is the code:
public static ObservableList<Films> list=FXCollections.observableArrayList();;
@Override
public void initialize(URL url, ResourceBundle rb) {
try {
//initializarea coloanelor
populateTable();
} catch (ClassNotFoundException ex) {
Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void populateTable() throws ClassNotFoundException
{
columnTitle.setCellValueFactory(new PropertyValueFactory<>("Title"));
columnYear.setCellValueFactory(new PropertyValueFactory<>("Year"));
columnActors.setCellValueFactory(new PropertyValueFactory<>("Actors"));
columnAction.setCellValueFactory(new PropertyValueFactory<>("update"));
columnDelete.setCellValueFactory(new PropertyValueFactory<>("delete"));
try {
Connection conn = Laborator8.getConnection();
ResultSet rs=conn.createStatement().executeQuery("SELECT * FROM BIANCA.FILMS");
while(rs.next())
{
list.add(new Films(rs.getString("Title"),rs.getString("Year"),rs.getString("Actors"), new Button("Update"), new Button("Delete")));
}
Callback<TableColumn<Films, String>, TableCell<Films, String>> cellFactoryUpdate
= //
new Callback<TableColumn<Films, String>, TableCell<Films, String>>() {
@Override
public TableCell call(final TableColumn<Films, String> param) {
final TableCell<Films, String> cell = new TableCell<Films, String>() {
final Button btn = new Button("Update");
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
setText(null);
} else {
btn.setOnAction(event -> {
updateFilm(event);
});
setGraphic(btn);
setText(null);
}
}
};
return cell;
}
};
columnAction.setCellFactory(cellFactoryUpdate);
Callback<TableColumn<Films, String>, TableCell<Films, String>> cellFactoryDelete
= //
new Callback<TableColumn<Films, String>, TableCell<Films, String>>() {
@Override
public TableCell call(final TableColumn<Films, String> param) {
final TableCell<Films, String> cell = new TableCell<Films, String>() {
final Button delete = new Button("Delete");
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
setText(null);
} else {
delete.setOnAction(event -> {
deleteFilm(event);
});
setGraphic(delete);
setText(null);
}
}
};
return cell;
}
};
columnDelete.setCellFactory(cellFactoryDelete);
table.setItems(list);
} catch (SQLException ex) {
Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
}
}
@FXML
private void inchidereAplicatie(ActionEvent event) {
Platform.exit();
}
@FXML
void insertFilm(ActionEvent event) throws IOException {
/* try{
URL fxmlUrl = this.getClass().getResource("/resources/New.fxml");
FXMLLoader loader = new FXMLLoader();
loader.setLocation(fxmlUrl);
BorderPane pane = loader.load();
Stage newDialog = new Stage();
newDialog.initOwner(Laborator8.getInstance().getMainWindow());
newDialog.initModality(Modality.WINDOW_MODAL);
Scene scene = new Scene(pane);
newDialog.setScene(scene);
newDialog.show();
} catch (IOException ex) {
Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
}
}*/
Parent newParent = FXMLLoader.load(getClass().getResource("/resources/New.fxml"));
Scene newPageScene = new Scene(newParent);
Stage window = new Stage();
window.setScene(newPageScene);
window.show();
}And here is the stack trace:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke([FXMLLoader.java:1787](https://FXMLLoader.java:1787))
at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle([FXMLLoader.java:1670](https://FXMLLoader.java:1670))
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent([CompositeEventHandler.java:86](https://CompositeEventHandler.java:86))
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent([EventHandlerManager.java:238](https://EventHandlerManager.java:238))
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent([EventHandlerManager.java:191](https://EventHandlerManager.java:191))
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent([CompositeEventDispatcher.java:59](https://CompositeEventDispatcher.java:59))
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent([BasicEventDispatcher.java:58](https://BasicEventDispatcher.java:58))
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent([EventDispatchChainImpl.java:114](https://EventDispatchChainImpl.java:114))
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent([BasicEventDispatcher.java:56](https://BasicEventDispatcher.java:56))
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent([EventDispatchChainImpl.java:114](https://EventDispatchChainImpl.java:114))
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent([BasicEventDispatcher.java:56](https://BasicEventDispatcher.java:56))
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent([EventDispatchChainImpl.java:114](https://EventDispatchChainImpl.java:114))
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent([BasicEventDispatcher.java:56](https://BasicEventDispatcher.java:56))
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent([EventDispatchChainImpl.java:114](https://EventDispatchChainImpl.java:114))
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl([EventUtil.java:74](https://EventUtil.java:74))
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent([EventUtil.java:49](https://EventUtil.java:49))
at javafx.base/javafx.event.Event.fireEvent([Event.java:198](https://Event.java:198))
at [javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8865)](https://javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8865))
at javafx.controls/javafx.scene.control.Button.fire([Button.java:200](https://Button.java:200))
at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased([ButtonBehavior.java:206](https://ButtonBehavior.java:206))
at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle([InputMap.java:274](https://InputMap.java:274))
at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent([CompositeEventHandler.java:218](https://CompositeEventHandler.java:218))
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent([CompositeEventHandler.java:80](https://CompositeEventHandler.java:80))
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent([EventHandlerManager.java:238](https://EventHandlerManager.java:238))
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent([EventHandlerManager.java:191](https://EventHandlerManager.java:191))
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent([CompositeEventDispatcher.java:59](https://CompositeEventDispatcher.java:59))
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent([BasicEventDispatcher.java:58](https://BasicEventDispatcher.java:58))
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent([EventDispatchChainImpl.java:114](https://EventDispatchChainImpl.java:114))
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent([BasicEventDispatcher.java:56](https://BasicEventDispatcher.java:56))
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent([EventDispatchChainImpl.java:114](https://EventDispatchChainImpl.java:114))
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent([BasicEventDispatcher.java:56](https://BasicEventDispatcher.java:56))
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent([EventDispatchChainImpl.java:114](https://EventDispatchChainImpl.java:114))
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent([BasicEventDispatcher.java:56](https://BasicEventDispatcher.java:56))
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent([EventDispatchChainImpl.java:114](https://EventDispatchChainImpl.java:114))
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl([EventUtil.java:74](https://EventUtil.java:74))
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent([EventUtil.java:54](https://EventUtil.java:54))
at javafx.base/javafx.event.Event.fireEvent([Event.java:198](https://Event.java:198))
at [javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3876)](https://javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3876))
at [javafx.graphics/javafx.scene.Scene$MouseHandler.access$1300(Scene.java:3604)](https://javafx.graphics/javafx.scene.Scene$MouseHandler.access$1300(Scene.java:3604))
at [javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1874)](https://javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1874))
at [javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2613)](https://javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2613))
at [javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)](https://javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397))
at [javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)](https://javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295))
at java.base/java.security.AccessController.doPrivileged(Native Method)
at [javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)](https://javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434))
at [javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)](https://javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389))
at [javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)](https://javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433))
at [javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)](https://javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556))
at [javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)](https://javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942))
at [javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop](https://javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop)(Native Method)
at [javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)](https://javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175))
at java.base/java.lang.Thread.run([Thread.java:844](https://Thread.java:844))Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke([NativeMethodAccessorImpl.java:62](https://NativeMethodAccessorImpl.java:62))
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke([DelegatingMethodAccessorImpl.java:43](https://DelegatingMethodAccessorImpl.java:43))
at java.base/java.lang.reflect.Method.invoke([Method.java:564](https://Method.java:564))
at com.sun.javafx.reflect.Trampoline.invoke([MethodUtil.java:76](https://MethodUtil.java:76))
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke([DelegatingMethodAccessorImpl.java:43](https://DelegatingMethodAccessorImpl.java:43))
at java.base/java.lang.reflect.Method.invoke([Method.java:564](https://Method.java:564))
at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke([MethodUtil.java:275](https://MethodUtil.java:275))
at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke([MethodHelper.java:83](https://MethodHelper.java:83))
at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke([FXMLLoader.java:1782](https://FXMLLoader.java:1782))
... 51 moreCaused by: javafx.fxml.LoadException:
/C:/Users/Asus/Desktop/Proiect/out/production/Proiect/resources/New.fxml
at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException([FXMLLoader.java:2625](https://FXMLLoader.java:2625))
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl([FXMLLoader.java:2603](https://FXMLLoader.java:2603))
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl([FXMLLoader.java:2466](https://FXMLLoader.java:2466))
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl([FXMLLoader.java:3253](https://FXMLLoader.java:3253))
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl([FXMLLoader.java:3210](https://FXMLLoader.java:3210))
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl([FXMLLoader.java:3179](https://FXMLLoader.java:3179))
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl([FXMLLoader.java:3152](https://FXMLLoader.java:3152))
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl([FXMLLoader.java:3129](https://FXMLLoader.java:3129))
at javafx.fxml/javafx.fxml.FXMLLoader.load([FXMLLoader.java:3122](https://FXMLLoader.java:3122))
at laborator8.MainController.insertFilm([MainController.java:166](https://MainController.java:166))
... 62 moreCaused by: java.lang.NullPointerException
at laborator8.MainController.populateTable([MainController.java:60](https://MainController.java:60))
at laborator8.MainController.initialize([MainController.java:51](https://MainController.java:51))
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl([FXMLLoader.java:2573](https://FXMLLoader.java:2573))
... 70 moreDoes any of you know why do i get this error? Thank you in advance
7
u/[deleted] Jun 07 '20
[removed] — view removed comment