有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JavaFX将peopleList分配给peopleTableView

鉴于我得到的项目清单如下:

List<People> peopleList = DbConnection.getPeople();

然后如何将其分配给我的tableView:

<TableView fx:id="peopleTableView" layoutY="-7.0" prefHeight="200.0" prefWidth="800.0">
    <columns>
        <TableColumn prefWidth="140.0" text="First Name" fx:id="fName"/>
        <TableColumn prefWidth="140.0" text="Surname" fx:id="sName"/>
        <TableColumn prefWidth="100.0" text="Gender" fx:id="gender"/>
        <TableColumn prefWidth="100.0" text="Sex" fx:id="sex"/>
    </columns>
</TableView>

我尝试了以下方法:

    DbConnection.connect();
    ObservableList<People> peopleObservableList = DbConnection.getAllPeople();
    FilteredList<People> peopleFilteredList = new FilteredList<>(peopleObservableList, p -> true);
    SortedList<People> sortedList = new SortedList<>(peopleFilteredList);
sortedList.comparatorProperty().bind(peopleTableView.comparatorProperty());
    peopleTableView.setItems(sortedList);

但会出现以下错误:

NullPointerException


共 (0) 个答案