Griffon JavaFX:视图抛出与模型相关的NPE
我正在进军狮鹫世界,我下载了一个小的lazybones应用程序,它会抛出错误。我的看法是这样的Griffon JavaFX:视图抛出与模型相关的NPE,java,model-view-controller,groovy,javafx,griffon,Java,Model View Controller,Groovy,Javafx,Griffon,我正在进军狮鹫世界,我下载了一个小的lazybones应用程序,它会抛出错误。我的看法是这样的 @ArtifactProviderFor(GriffonView) class PennyPackerView { FactoryBuilderSupport builder PennyPackerController controller PennyPackerModel model void initUI() { builder.application(title: applicatio
@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");
}
我不知道为什么会发生这种情况,也不知道如何解决它=问题是下面这行
text: bind(model.clickCount))
应该是
text: bind(model.clickCountProperty))
第一个返回一个普通值,而第二个返回一个JavaFX属性。我很惊讶你发现了这个问题,因为对源代码的快速grep会产生以下结果
$ grep clickCount -r griffon-javafx-* | grep bind
griffon-javafx-groovy-templates/templates/griffon-javafx-groovy/griffon-app/views/View.groovy: text: bind(model.clickCountProperty()))
griffon-javafx-groovy-templates/templates/subtmpl-artifact/View.groovy: text: bind(model.clickCountProperty()))
griffon-javafx-java-templates/templates/griffon-javafx-java/griffon-app/views/View.java: model.clickCountProperty().bindBidirectional(clickLabel.textProperty());
griffon-javafx-java-templates/templates/subtmpl-artifact/View.java: model.clickCountProperty().bindBidirectional(clickLabel.textProperty());