使用JAVAFX同时更新两个tableview中的数据时出现NullPointerException

时间:2017-12-05 07:25:59

标签: java javafx java-threads

我正在使用JavaFX进行测试项目,其中正在使用两个表视图。每个表有两列。 GUI是在FXML文件中设计的。 运行应用程序时,它会使用不同的线程不断更新列数据。 但是在程序执行一段时间后,它会产生NullPointerException,如下所示:

request.connection.remoteAddress 

or

const ip = req.socket.localAddress;
const port = req.socket.localPort;

仅供参考,让我分享fxml文件和控制器类java文件。

FXMLDocument.fxml

Exception in thread "Thread-4" java.lang.NullPointerException
    at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
    at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
    at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
    at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
    at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
    at javafx.scene.control.TableView$TableViewFocusModel.setFocusedCell(TableView.java:3233)
    at javafx.scene.control.TableView$TableViewFocusModel.focus(TableView.java:3278)
    at javafx.scene.control.TableView$TableViewFocusModel.updateDefaultFocus(TableView.java:3423)
    at javafx.scene.control.TableView$TableViewFocusModel.updateItemsObserver(TableView.java:3208)
    at javafx.scene.control.TableView$TableViewFocusModel.access$2200(TableView.java:3125)
    at javafx.scene.control.TableView$TableViewFocusModel$1.invalidated(TableView.java:3156)
    at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
    at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:105)
    at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
    at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
    at javafx.scene.control.TableView.setItems(TableView.java:843)
    at com.example.jfx.FXMLDocumentController$1.lambda$run$0(FXMLDocumentController.java:95)
    at java.lang.Thread.run(Thread.java:745)

FXMLDocumentController.java

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="528.0" prefWidth="625.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="com.example.jfx.FXMLDocumentController">
   <children>
      <Label layoutX="14.0" layoutY="14.0" prefHeight="15.0" prefWidth="119.0" text="TableViewTestApp" />
      <HBox layoutY="35.0" prefHeight="493.0" prefWidth="625.0">
         <children>
            <TableView fx:id="tblCountryPopulation" prefHeight="493.0" prefWidth="292.0">
              <columns>
                <TableColumn fx:id="tcCountryName" prefWidth="105.0" text="CountryName" />
                <TableColumn fx:id="tcPopulation" prefWidth="83.0" text="Population" />
              </columns>
            </TableView>
            <Separator orientation="VERTICAL" prefHeight="493.0" prefWidth="46.0" />
            <TableView fx:id="tblCityPopulation" prefHeight="493.0" prefWidth="281.0">
              <columns>
                <TableColumn fx:id="tcCityName" text="CityName" />
                <TableColumn fx:id="tcCityPopulation" prefWidth="113.0" text="CityPopulation" />
              </columns>
            </TableView>
         </children>
      </HBox>
   </children>
</AnchorPane>

如果有任何帮助,我们将非常感激。 如果已存在类似问题,请提前道歉。 感谢。

0 个答案:

没有答案