org.datafx.provider.PublishingTask $ 1.run(PublishingTask.java:41)中的java.lang.NullPointerException

时间:2015-04-15 06:43:13

标签: java rest javafx java-8

使用datafx从rest脚本中读取json。 以下是代码

    @FXML
private void handleButtonAction(ActionEvent event) {
    System.out.println("You clicked me!");
    label.setText("Hello World!");
    JsonConverter jsonConvert = new JsonConverter("jsonCase", CaseTable.class);
    RestSource test = RestSourceBuilder.create()
                      .converter(jsonConvert)
                      .host("http://devel.com.au")
                      .path("cgi-bin").path("ssinternalweb-jcgi.sh")
                      .queryParam("Program", "appfx/CaseTest.p")
                      .queryParam("ProcName", "FXRequest")
                      .queryParam("TestParam", "aValue").build();
    ListDataProvider<CaseTable> ldp = ListDataProviderBuilder.create()
            .dataReader(test)
            .build();
    Worker<ObservableList<CaseTable>>retrieve = ldp.retrieve();      
    lvCases.setItems(retrieve.getValue());                                                                                      
}

@Override
public void initialize(URL url, ResourceBundle rb) {
    lvCases.setCellFactory(l -> new CaseTableCell());
    lvCases.getItems().add(new CaseTable(999, "Loading..."));
}  

当工作人员开始处理结果时,我收到以下错误消息

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at org.datafx.provider.PublishingTask$1.run(PublishingTask.java:41)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1175034525.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/501263526.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/96639997.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)

我有一个突破点,我试图创建的类似乎正在接收正确的值。只有问题没有显示在列表视图的屏幕上。

private ListView<CaseTable> lvCases;

1 个答案:

答案 0 :(得分:2)

如我的其中一条评论所述,应设置结果列表,不会收到此错误消息。不同的界限是为什么思想没有关系但事实证明是完全相同的问题。 以下是现在可以使用的更新代码。

    @FXML
private void handleButtonAction(ActionEvent event) {
    JsonConverter jsonConvert = new JsonConverter("jsonCase", CaseTable.class);
    RestSource test = RestSourceBuilder.create()
                      .converter(jsonConvert)
                      .host("http://devel.com.au")
                      .path("cgi-bin").path("ssinternalweb-jcgi.sh")
                      .queryParam("Program", "appfx/CaseTest.p")
                      .queryParam("ProcName", "FXRequest")
                      .queryParam("TestParam", "aValue").build();
    lvCases.getItems().removeAll(lvCases.getItems());
    ListDataProvider<CaseTable> ldp = ListDataProviderBuilder.create()
            .dataReader(test)
            .resultList(lvCases.getItems())
            .build();
    Worker<ObservableList<CaseTable>>retrieve = ldp.retrieve();                                                                                         
}

@Override
public void initialize(URL url, ResourceBundle rb) {
    lvCases.setCellFactory(l -> new CaseTableCell());
    lvCases.getItems().add(new CaseTable(999, "Loading..."));
}   

有关详细信息,请参阅此处

https://bitbucket.org/datafx/datafx/issue/9/npe-when-resultlist-not-specified