JAVA FXCollections LoadException类不是有效类型

Mat*_*hli 7 java javafx fxml fxmlloader

我正试图在本教程的帮助下用一些数据实现TableView .

我坚持将数据从我的"Person.java"填充到TableView.

我将问题跟踪到<Person firstName="Jacob" lastName="Smith" email="jacob.smith@example.com" />最底部的"fxmltableview.fxml"文件中的部分.

因此,似乎由于某种原因,我的"observableArrayList"并不是全部包含"Person.java"对象.允许"String.java".因为我在教程中逐字逐句地读了几遍,所以我没有对文件进行任务的想法,我没有看到我的文件之间有任何区别.每当我删除<Person someStuff/>它工作正常.

我怎样才能摆脱这个烦人的错误?

引发者:javafx.fxml.LoadException:Person不是有效类型./D:/workspace/TableViewExampleFXML/bin/application/fxmltableview.fxml:40

FXML-文件:

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

<?import fxmltableview.*?>

<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.cell.PropertyValueFactory?>

<?import javafx.scene.layout.GridPane?>

<?import javafx.collections.FXCollections?>


<GridPane alignment="CENTER" hgap="10.0" maxHeight="-Infinity"
    maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
    prefHeight="400.0" prefWidth="600.0" vgap="10.0" xmlns="http://javafx.com/javafx/8"
    xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.FXMLTableViewController">

    <TableView fx:id="tableView" prefHeight="200.0" prefWidth="200.0"
        GridPane.columnIndex="0" GridPane.rowIndex="1">
        <columns>
            <TableColumn prefWidth="75.0" text="First Name">
                <cellValueFactory>
                    <PropertyValueFactory property="firstName" />
                </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="75.0" text="Last Name">
                <cellValueFactory>
                    <PropertyValueFactory property="lastName" />
                </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="75.0" text="Email Address">
                <cellValueFactory>
                    <PropertyValueFactory property="email" />
                </cellValueFactory>
            </TableColumn>
        </columns>
        <items>
            <FXCollections fx:factory="observableArrayList">
                <Person firstName="Jacob" lastName="Smith" email="jacob.smith@example.com" />
            </FXCollections>
        </items>
    </TableView>
</GridPane>
Run Code Online (Sandbox Code Playgroud)

"Person.java"是从教程中复制/粘贴的,这就是为什么我很沮丧,以至于它对我不起作用.无论如何,我会把它贴在这里.

package application;

import javafx.beans.property.SimpleStringProperty;

public class Person {
  private final SimpleStringProperty firstName = new SimpleStringProperty("");
  private final SimpleStringProperty lastName = new SimpleStringProperty("");
  private final SimpleStringProperty email = new SimpleStringProperty("");

  public Person() {
    this("", "", "");
  }

  public Person(String firstName, String lastName, String email) {
    setFirstName(firstName);
    setLastName(lastName);
    setEmail(email);
  }

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

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

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

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

  public String getEmail() {
    return email.get();
  }

  public void setEmail(String fName) {
    email.set(fName);
  }
}
Run Code Online (Sandbox Code Playgroud)

Jam*_*s_D 10

您更改了Person类的包名称.在本教程中,包名称是fxmltableview您所拥有的位置application.您没有相应地更改导入.所以你需要

<?import application.Person ?>
Run Code Online (Sandbox Code Playgroud)

代替

<?import fxmltableview.* ?>
Run Code Online (Sandbox Code Playgroud)