Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA FXCollections LoadException Class is not a valid type

I'm trying to implement a TableView with some data with the help of this Tutorial.

Im stuck on populating data from my "Person.java" to the TableView.

I tracked the problem down to the part <Person firstName="Jacob" lastName="Smith" email="[email protected]" /> inside the "fxmltableview.fxml" file at the very bottom.

So it seems that for some reason my "observableArrayList" isn't allwed to contain "Person.java" objects. "String.java" is allowed. Im out of ideas for experementing with the files, as i read several times word by word through the tutorial and i don't see any difference between my files. Whenever i remove the <Person someStuff/> it works fine.

How can i get rid of this annoying error?

Caused by: 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="[email protected]" />
            </FXCollections>
        </items>
    </TableView>
</GridPane>

The "Person.java" is copy/pasted from the tutorial thats why im so frustrated that it doesn't work for me. Anyway i will 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);
  }
}
like image 926
Matthis Kohli Avatar asked Sep 10 '15 12:09

Matthis Kohli


1 Answers

You changed the package name for your Person class. In the tutorial, the package name is fxmltableview, where you have application. You didn't change the import accordingly. So you need

<?import application.Person ?>

instead of

<?import fxmltableview.* ?>
like image 192
James_D Avatar answered Oct 22 '22 08:10

James_D