JAVA FXCollections class exception class is not valid

I am trying to implement a TableView with some data using this Tutorial .

I am stuck filling data from my "Person.java" into a TableView.

I traced the problem to the part <Person firstName="Jacob" lastName="Smith" email="jacob.smith@example.com" />inside the file "fxmltableview.fxml" at the very bottom.

So it seems that for some reason, my "observableArrayList" should not contain Person.java objects. "String.java" is allowed. I am out of ideas for experimenting with files, as I read several times word for word through a tutorial, and I don't see the difference between my files. Whenever I delete <Person someStuff/>, it works great.

How can I get rid of this annoying mistake?

Called: javafx.fxml.LoadException: The face is not a valid type. /D:/workspace/TableViewExampleFXML/bin/application/fxmltableview.fxml:40

FXML file:

<?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>

"Person.java" is copied / pasted from the tutorial, so I'm so disappointed that it does not work for me. Anyway, I paste it here.

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);
  }
}
+4
source share
1 answer

You have changed the package name for your class Person. In the tutorial, the name of the package fxmltableviewwhere you have it application. You have not changed the import accordingly. Therefore you need

<?import application.Person ?>

instead

<?import fxmltableview.* ?>
+7
source

Source: https://habr.com/ru/post/1606778/


All Articles