经过一些调试后,我对错误有了可能的解释,但遗憾的是没有解决方案。
如果你没有运行<nestedCellValueFactory>
标签,正如您已经报告的那样,您将收到此异常:
Caused by: javafx.fxml.LoadException: Element does not define a default property.
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$Element.set(FXMLLoader.java:180)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:790)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
所以去FXMLLoader
跟踪异常的来源你会发现:
790 号线:parent.set(value);
, where parent
是一个实例FXMLLoader$InstanceDeclarationElement
, 与类型<your.package.name>. NestablePropertyValueFactory
, and value
is a PropertyValueFactory
object.
-
第 177-183 行:
public void set(Object value) throws LoadException {
...
Class<?> type = this.value.getClass();
DefaultProperty defaultProperty = type.getAnnotation(DefaultProperty.class);
if (defaultProperty == null) {
throw constructLoadException("Element does not define a default property.");
}
getProperties().put(defaultProperty.value(), value);
}
人们可以预料到defaultProperty.value()
应该"nestedCellValueFactory"
,并且值会被赋值,但是抛出的异常清楚地表明情况并非如此,所以defaultProperty
应该为空。
发生的情况可以通过检查来解释Class<?> type
:
type: class com.sun.javafx.fxml.builder.ProxyBuilder
So type
不是你的NestablePropertyValueFactory
类,但是一个ProxyBuilder
.
现在,如果你检查该类,则没有@DefaultProperty
注释,因此defaultProperty
为 null 并且抛出异常。
该代理创建于javafx.fxml.JavaFXBuilderFactory::getBuilder
,基于真实类型:
if (scanForConstructorAnnotations(type)) {
builder = new ProxyBuilder(type);
}
但它返回ProxyBuilder
相反,在这个过程中DefaultProperty
注释丢失。
代理构建器似乎适用于带有注释的构造函数的类@NamedArg
, but not为了@DefaultProperty
注解。
虽然这可能是您的班级的情况,但应该有比简短的异常消息更好的解释。
无论如何,由于当您添加标签并删除默认注释时构建器工作正常,我只会考虑删除@DefaultProperty
.