Ciao a tutti,
da poco ho iniziato a programmare in JavaFX, al momento mi trovo davanti ad un errore che è da circa 1 settimana che non ne vengo fuori, il programma dovrebbe funzionare in questo modo:
l'utente seleziona un menu tramite la "menubar", una volta selezionato il programma apre un'altra finestra ed inizia a caricare i dati all'interno della TableView prelevandoli dal server.
purtroppo quest'ultimo passaggio non riesco a portarlo a termine.
l'errore che mi viene visualizzato è:
java.lang.NullPointerException
at application.RepairExtractTool.[b]buildData[/b](RepairExtractTool.java:265)
at application.RepairExtractTool.globalWip(RepairExtractTool.java:113)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1782)
at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1670)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.controls/javafx.scene.control.MenuItem.fire(MenuItem.java:465)
at javafx.controls/com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1380)
at javafx.controls/com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.lambda$createChildren$12(ContextMenuContent.java:1333)
at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3851)
at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1200(Scene.java:3579)
at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2588)
at 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)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at 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:390)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
at 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:174)
at java.base/java.lang.Thread.run(Thread.java:832)
Error on Building Data
il tasto che crea la finestra secondaria è:
public void globalWip(ActionEvent actionEvent) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("GlobalWip.fxml"));
Scene scene2 = new Scene(root);
Stage secondStage = new Stage();
secondStage.setTitle("Repair Extract Tool");
secondStage.setScene(scene2);
buildData();
secondStage.show();
}
mentre il metodo buildData() [il metodo che dovrebbe caricare i dati e che mi sta dando parecchie difficoltà]
public void buildData(){
data = FXCollections.observableArrayList();
String connectionUrl = "jdbc:sqlserver://.......hidden........................";
try(Connection connection = DriverManager.getConnection(connectionUrl);){
java.sql.Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(globalWip); //script
while(rs.next()){
ListTableGlobalWip cm = new ListTableGlobalWip(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9),
rs.getString(10), rs.getString(11), rs.getString(12), rs.getString(13), rs.getString(14), rs.getString(15), rs.getString(16), rs.getString(17), rs.getString(18), rs.getString(19), rs.getString(20),
rs.getString(21), rs.getString(22), rs.getString(23), rs.getString(24), rs.getString(25), rs.getString(26), rs.getString(27), rs.getString(28), rs.getString(29), rs.getString(30), rs.getString(31),
rs.getString(32), rs.getString(33), rs.getString(34), rs.getString(35), rs.getString(36), rs.getString(37), rs.getString(38), rs.getString(39), rs.getString(40), rs.getString(41), rs.getString(42),
rs.getString(43), rs.getString(44), rs.getString(45));
cm.technical_Unit_Id.set(rs.getString("technical_Unit_Id"));
cm.RMA_ID.set(rs.getString("RMA_ID"));
cm.GlobalNameCode.set(rs.getString("GlobalNameCode"));
cm.GLobalName.set(rs.getString("GLobalName"));
............
...........
............
..........
..........
...........
...........
data.add(cm);
}
MainTableGlobalWip.setItems(data);
connection.close();
}
catch(Exception e){
e.printStackTrace();
System.out.println("Error on Building Data");
}
}
tutte le colonne PENSO di aver settate anche in modo corretto
public void setColumns() {
technical_Unit_Id.setCellValueFactory(new PropertyValueFactory<>("technical_Unit_Id"));
RMA_ID.setCellValueFactory(new PropertyValueFactory<>("RMA_ID"));
GlobalNameCode.setCellValueFactory(new PropertyValueFactory<>("GlobalNameCode"));
.......................
....................
................
}
@FXML private TableView<ListTableGlobalWip> MainTableGlobalWip;
@FXML private TableColumn<ListTableGlobalWip,String> ............;//fx:id della colonna
@FXML private TableColumn<ListTableGlobalWip,String> ............;//fx:id della colonna
@FXML private TableColumn<ListTableGlobalWip,String> ............;//fx:id della colonna
@FXML private TableColumn<ListTableGlobalWip,String> ............;
all'interno del file FXML penso di aver dichiarto in modo corretto anche la parte della TableView
<TableView fx:id="MainTableGlobalWip" editable="true" layoutX="3.0" layoutY="25.0" prefHeight="702.0" prefWidth="1184.0" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="64.0">
<columns>
spero che mi possiate aiutare, nel frattempo vi ringrazio per il vostro tempo
Luca