JAVA FXCollections LoadException类不是有效类型
我试图在这个
Tutorial的帮助下用一些数据实现一个TableView.
我坚持将数据从我的“Person.java”填充到TableView. 我将问题追溯到部分< Person firstName =“Jacob”lastName =“Smith”email =“jacob.smith@example.com”/>在最底部的“fxmltableview.fxml”文件中. 因此,似乎由于某种原因,我的“observableArrayList”并不是全部包含“Person.java”对象.允许使用“String.java”. 我该如何摆脱这个恼人的错误? 引发者:javafx.fxml.LoadException:Person不是有效类型. 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> “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); } } 解决方法
您更改了Person类的包名称.在本教程中,包名称是fxmltableview,您可以在其中使用应用程序.您没有相应地更改导入.所以你需要
<?import application.Person ?> 代替 <?import fxmltableview.* ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |