The Java fxcollections loadexception class is not a valid type

I try to implement a tableview with some data with the help of tutorial

I insist on populating the data from my "person. Java" into tableview

I traced the problem back to the section < person firstname = "Jacob" LastName = "Smith" email = "Jacob smith@example.com ”/>In the "fxmltableview. Fxml" file at the bottom

Therefore, it seems that for some reason, my "observable ArrayList" does not contain all "person. Java" objects "String. Java" is allowed Because I read it word by word in the tutorial, and I didn't see any difference between my files, I didn't have the idea of working on the files Whenever I delete < person somestuff / > it works normally

How can I get rid of this annoying mistake?

Initiator: JavaFX fxml. Loadexception: person 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, which is why I am so frustrated that it doesn't work for me Anyway, I'll stick 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);
  }
}

Solution

You changed the package name of the person class In this tutorial, the package name is fxmltableview, where you can use the application You have not changed the import accordingly So you need

<?import application.Person ?>

replace

<?import fxmltableview.* ?>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>