JAVA FXCollections LoadException类不是有效类型 [英] JAVA FXCollections LoadException Class is not a valid type

查看:354
本文介绍了JAVA FXCollections LoadException类不是有效类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用这个教程

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

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

我将问题追溯到部分< Person firstName =JacoblastName =Smithemail =jacob.smith@example.com/> 在最底部的fxmltableview.fxml文件中。

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

所以看起来由于某种原因,我的observableArrayList并不是全部包含Person。 java对象。允许String.java。
Im出于对文件进行实验的想法,因为我在教程中逐字逐句阅读,我看不出我的文件之间有任何区别。每当我删除< Person someStuff /> 时,它都能正常工作。

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?

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

Caused by: javafx.fxml.LoadException: Person is not a valid type. /D:/workspace/TableViewExampleFXML/bin/application/fxmltableview.fxml:40

FXML-File:

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是从教程中复制/粘贴的,这就是为什么我很沮丧它没有不适合我。无论如何,我会把它贴在这里。

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);
  }
}


推荐答案

你更改了 Person 类的包名称。在本教程中,包名称为 fxmltableview ,其中包含 application 。您没有相应地更改导入。所以你需要

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

而不是

<?import fxmltableview.* ?>

这篇关于JAVA FXCollections LoadException类不是有效类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆