Update: Die Ursache ist tblTimeDataClock ist null.Any Idee warum?TableView getItems.AddAll verursacht java.lang.reflect.InvocationTargetException
Ich erhalte eine TableView getItems.AddAll verursacht java.lang.reflect.InvocationTargetException beim Aufruf der getItems(). AddAll() -Methode. Ich habe versucht, den verschiedenen Beispielen im Internet zu folgen, aber nichts scheint so zu funktionieren. Die Ausnahme tritt beim Aufruf tblTimeDataClock.getItems(). AddAll (data) auf.
Ich sehe eine Warnung für den neuen PropertyValue-Aufruf, der Argumente für den redundanten Typ im neuen Ausdruck sagt. Nicht sicher, ob das etwas damit zu tun hat,
Was mache ich falsch?
Ich habe dieses abgekürzte Beispiel zusammengestellt.
@FXML
private TableView<Test> tblTimeDataClock;
@FXML
private TableColumn<Test, String> colTimeSeconds;
@FXML
private TableColumn<Test, String> colDataVolts;
@FXML
private TableColumn<Test, String> colClockVolts;
@Override
public void initialize(URL url, ResourceBundle rb) {
listTimeDataClockMeasurement = new <Test>ArrayList();
colTimeSeconds.setCellValueFactory(new PropertyValueFactory<Test, String>("n1"));
colDataVolts.setCellValueFactory(new PropertyValueFactory<Test, String>("n2"));
colDataVolts.setCellValueFactory(new PropertyValueFactory<Test, String>("n3"));
ObservableList<Test> data = FXCollections.observableArrayList();
tblTimeDataClock.getItems().addAll(data);
}
Die Test-Klasse
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class Test {
private final SimpleStringProperty n1;
private final SimpleStringProperty n2;
private final SimpleStringProperty n3;
public String getN1() {
return n1.get();
}
public String getN2() {
return n2.get();
}
public String getN3() {
return n3.get();
}
public Test(String n1, String n2, String n3) {
this.n1 = new SimpleStringProperty(n1);
this.n2 = new SimpleStringProperty(n2);
this.n3 = new SimpleStringProperty(n3);
}
}
FXML pro Anfrage
hinzugefügt <content>
<TableView fx:id="tblDataClock" prefHeight="200.0" prefWidth="200.0">
<columns>
<TableColumn fx:id="colTimeSeconds" prefWidth="116.0" text="Time" />
<TableColumn id="colData" fx:id="colDataVolts" prefWidth="127.0" text="Data" />
<TableColumn id="colClock" fx:id="colClockVolts" prefWidth="137.0" text="Clock" />
</columns>
</TableView>
</content>
die Ursache Sieht aus wie java.lang.NullPointerException bei serialdecoder.SerialDecoderController sein könnte. initialisieren (SerialDecoderController.java:60)
Exception in Application start method
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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
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.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException:
file:/E:/Data/Java/SerialDecoder/dist/run67790734/SerialDecoder.jar!/serialdecoder/SerialDecoder.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 serialdecoder.SerialDecoder.start(SerialDecoder.java:22)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
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)
... 1 more
Caused by: java.lang.NullPointerException
at serialdecoder.SerialDecoderController.initialize(SerialDecoderController.java:60)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 17 more
Exception running application serialdecoder.SerialDecoder
Was die Ausnahme für die Sache der Nachricht & Stack-Trace ist? – SLaks
Sie sollten wahrscheinlich die FXML sowie den gesamten Stack-Trace schreiben. –
sind Sie sicher, dass das Objekt, auf dem Sie anrufen 'addAll()' die Operation unterstützt ? Diese Methode ist eine dieser blanky-blank "optionalen" im Collection-Paket. – arcy