JavaFX - 将peopleList分配给peopleTableView

时间:2018-05-12 20:13:55

标签: java javafx fxml

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

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 个答案:

没有答案