我的简单 table 视图在 javaFX 中不起作用

My simple table view doesn't work in javaFX

我是 javaFx 的初学者,我现在正在在线的帮助下将我的 Person 对象的数据插入到我的 tableView toturials.But 我的代码有一些 problems.There 既不是编译时间也不是 运行次errors.But我的tableView.Being一个javaFx的初学者,查了很久我的代码time.But不知道为什么is.Could你看一下好吗?这是我的模态 class,Person.java

public class Person {
        public  SimpleStringProperty firstName;
        public SimpleStringProperty lastName;

        public Person(String fName, String lName) {
            this.firstName = new SimpleStringProperty(fName);
            this.lastName = new SimpleStringProperty(lName);
        }
}

这是我的控制器class

public class FXMLDocumentController implements Initializable {

    private ObservableList<Person> personData = FXCollections.observableArrayList();

   @FXML
   private TableView<Person> table;
     @FXML
    private TableColumn<Person, String> col1;
    @FXML
    private TableColumn<Person, String> col2;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
         col1.setCellValueFactory(
            new PropertyValueFactory<Person,String>("firstName")
        );

        col2.setCellValueFactory(
            new PropertyValueFactory<Person,String>("lastName")
            );  
        personData.add(new Person("John","Leon"));
        System.out.println("data to collection added");
        table.setItems(personData);
        System.out.println("collection  to table added");


    }    

}

这是我的 FXML 代码

<AnchorPane id="AnchorPane" prefHeight="332.0" prefWidth="409.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="fucktable.FXMLDocumentController">
    <children>
      <TableView fx:id="table" layoutX="42.0" layoutY="54.0" prefHeight="200.0" prefWidth="200.0">
        <columns>
          <TableColumn fx:id="col1" prefWidth="75.0" text="C1" />
          <TableColumn fx:id="col2" prefWidth="75.0" text="C2" />
        </columns>
      </TableView>
    </children>
</AnchorPane>

感谢您的关注

您的 Person class 中应该有这些方法:

public String getFirstName() {
    return firstName.get();
}

public void setFirstName(String s) {
    firstName.set(s);
}

public String getLastName() {
    return lastName.get();
}

public void setLastName(String s) {
    lastName.set(s);
}