【发布时间】:2014-12-15 18:53:13
【问题描述】:
我正在涉足 Griffon 世界,我下载了一个小型的lazybones 应用程序,但它会引发错误。我的看法是这样的。
@ArtifactProviderFor(GriffonView)
class PennyPackerView {
FactoryBuilderSupport builder
PennyPackerController controller
PennyPackerModel model
void initUI() {
builder.application(title: application.configuration['application.title'],
sizeToScene: true, centerOnScreen: true, name: 'mainWindow') {
scene(fill: WHITE, width: 200, height: 60) {
gridPane {
label(id: 'clickLabel', row: 0, column: 0,
text: bind(model.clickCount))
button(row: 1, column: 0, prefWidth: 200,
controller.click())
}
}
}
}
}
使用 gradle:run 后,它会抛出一个错误,让我相信我的模型没有被注入,至少在绑定发生时是这样。
Warning, could not locate neither a JavaFX property nor a JavaBean property for class
javafx.scene.control.Label, property: '0'
[2014-10-20 13:30:56,166] [JavaFX Application Thread]
ERROR griffon.core.GriffonExceptionHandler
- Uncaught Exception
java.lang.NullPointerException: Cannot bind to null
at javafx.beans.property.StringPropertyBase.bind(StringPropertyBase.java:161)
at javafx.beans.property.Property$bind.call(Unknown Source)
at groovyx.javafx.factory.FXHelper$__clinit__closure26.doCall(FXHelper.groovy:454)
下面是模型代码,不是很复杂。
@ArtifactProviderFor(GriffonModel)
class PennyPackerModel {
@FXObservable String clickCount = "0"
}
非常感谢您就抛出此 NPE 的原因或任何其他问题提供任何帮助。我相信我从lazybones 中得到的是griffon-javafx-groovy 启动应用程序。
编辑:所以我一直在调试,看起来模型正在被注入,但是在设置绑定时出现了问题。在 StringPropertyBase 类中,传递给它的 newObservable 的值为 null。
public void bind(ObservableValue<? extends String> newObservable) {
if (newObservable == null) {
throw new NullPointerException("Cannot bind to null");
}
我不知道为什么会这样,或者如何解决它=(
【问题讨论】:
标签: java model-view-controller groovy javafx griffon