gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:28:28 26 4
gpt4 key购买 nike

使用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)

我在类中尝试创建的断点似乎正在接收正确的值。唯一的问题是没有在 ListView 的屏幕上显示。

private ListView<CaseTable> lvCases;

最佳答案

正如我的评论之一所述,应该设置结果列表,并且不会收到此错误消息。线路不同,这就是为什么思想不相关,但结果却是完全相同的问题。下面是现在可以使用的更新代码。

    @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

关于java.lang.NullPointerException 在 org.datafx.provider.PublishingTask$1.run(PublishingTask.java :41),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29643285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com