【发布时间】:2021-10-16 04:55:40
【问题描述】:
我正在尝试在 javafx 中的 tableView 中显示数据。
即使我使用了 SimpleStringProperty 和 SimpleIntegerProperty,但每次单击“检查客户”按钮时,我都会收到此错误:
原因:java.lang.IllegalAccessException:模块 javafx.base 无法访问类 application.customer(在模块 FCR 中),因为模块 FCR 没有打开应用程序到 javafx.base
在 javafx.base/com.sun.javafx.property.MethodHelper.invoke(MethodHelper.java:69)
在 javafx.base/com.sun.javafx.property.PropertyReference.getProperty(PropertyReference.java:197)
... 98 更多
这是客户的代码:
public class customer {
private final IntegerProperty ID;
private final StringProperty firstName;
private final StringProperty lastName;
private final StringProperty carPlate;
private final IntegerProperty telephoneNum;
public customer(int ID,String firstName, String lastName, String carPlate, int telephoneNum) {
this.ID = new SimpleIntegerProperty();
this.firstName = new SimpleStringProperty();
this.lastName = new SimpleStringProperty();
this.carPlate = new SimpleStringProperty();
this.telephoneNum = new SimpleIntegerProperty();
setID(ID);
setfirstName(firstName);
setlastName(lastName);
setcarPlate(carPlate);
settelephoneNum(telephoneNum);
}
public final StringProperty firstNameProperty() {
return firstName;
}
public final String getfirstName() {
return firstName.get();
}
public final void setfirstName(String fname) {
firstName.set(fname);
}
public final IntegerProperty IDProperty() {
return ID;
}
public final int getID() {
return ID.get();
}
public final void setID(int iD) {
ID.set(iD);
}
public final StringProperty lastNameProperty() {
return lastName;
}
public final String getlastName() {
return lastName.get();
}
public final void setlastName(String lname) {
lastName.set(getfirstName());;
}
public final IntegerProperty telephoneNumProperty() {
return telephoneNum;
}
public final int gettelephoneNum() {
return telephoneNum.get();
}
public final void settelephoneNum(int tnum) {
telephoneNum.set(tnum);;
}
public final StringProperty carPlateProperty() {
return carPlate;
}
public final String getcarPlate() {
return carPlate.get();
}
public final void setcarPlate(String platenum) {
carPlate.set(platenum);
}
这里是控制器:
public class checkCustomers {
private customersData q = Main.q;
@FXML
private TableView table;
@FXML
private TableColumn firstName;
@FXML
private TableColumn lastName;
@FXML
private TableColumn carPlate;
@FXML
private TableColumn telephoneNumber;
@FXML
public void initialize() {
System.out.println(1);
firstName.setCellValueFactory(new PropertyValueFactory<customer, String>("firstName"));
lastName.setCellValueFactory(new PropertyValueFactory<customer, String>("lastName"));
carPlate.setCellValueFactory(new PropertyValueFactory<customer, String>("carPlate"));
telephoneNumber.setCellValueFactory(new PropertyValueFactory<customer, Integer>("telephoneNumber"));
table.setItems(FXCollections.observableArrayList(q.getAllCustomers()));
}
module-info.java 代码为:
module FCR {
requires javafx.controls;
requires javafx.fxml;
requires java.sql;
requires javafx.base;
opens application to javafx.graphics, javafx.fxml;
}
我想我应该在模块信息中添加一些东西,有人可以帮忙吗?
【问题讨论】:
-
为什么不包括
opens application to javafx.graphics, javafx.fxml, javafx.base;?或者export application虽然不清楚什么是应用程序。 -
成功了!非常感谢!!!!
-
请遵守 java 命名约定