我无法弄清楚我的错误

时间:2015-09-14 14:28:57

标签: javafx nullpointerexception mqtt

我有一个JavaFX应用程序,它有一个来自服务器请求某些数据的scheduledExecutorService。这些数据用于填充ListView,当我单击此列表中的元素时,会向服务器发送更多数据的请求并设置MQTT连接,但几秒钟后我从somwhere得到NullPointerException我没有理解,我甚至不知道什么对象指向Null。

以下是错误来自的部分:

public class DevicePane extends BorderPane {

private final TcpConnection tcp;
private final MqttConnection mqtt;

private final DeviceListView deviceListView;
private SpecificDevicePane deviceInfoPane;

private String[] topicsArray;

public DevicePane() {
    tcp = new TcpConnection();
    mqtt = new MqttConnection();
    mqtt.connect();
    deviceListView = new DeviceListView();
    deviceListView.getSelectionModel().selectedIndexProperty().addListener(e -> {
        if (topicsArray != null) mqtt.unsubscribeToAll(topicsArray);
        AnswerMessage answer = tcp.sendRequest(new RequestMessage(RQST_DEVICE_INFO, deviceListView.getSelectionModel().getSelectedItem().toString()));
        topicsArray = new String[answer.getParams().size()];
        topicsArray = answer.getParams().toArray(topicsArray);
        mqtt.subscribeToAll(topicsArray);
        deviceInfoPane = new SpecificDevicePane(answer.getParams(), mqtt, tcp);
        ScrollPane scrollPane = new ScrollPane(deviceInfoPane);
        this.setCenter(scrollPane);
    });
    this.setLeft(deviceListView);
    // Tâche planifiée afin de récupérer la liste des objets IOT de la DB.
    ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(1);
    threadPool.scheduleAtFixedRate(() -> {
        refreshDeviceList();
    }, 0, 5, TimeUnit.SECONDS);
}

这是我得到的错误:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at view.DevicePane.lambda$new$8(DevicePane.java:36)
at view.DevicePane$$Lambda$77/576256602.invalidated(Unknown Source)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyIntegerWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:176)
at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:142)
at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:113)
at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:147)
at javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:68)
at javafx.scene.control.MultipleSelectionModelBase.clearSelection(MultipleSelectionModelBase.java:665)
at javafx.scene.control.ListView$ListViewBitSetSelectionModel.updateSelection(ListView.java:1306)
at javafx.scene.control.ListView$ListViewBitSetSelectionModel.access$1600(ListView.java:1173)
at javafx.scene.control.ListView$ListViewBitSetSelectionModel$1.onChanged(ListView.java:1246)
at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
at javafx.collections.ModifiableObservableListBase.setAll(ModifiableObservableListBase.java:90)
at view.DeviceListView.refreshShownDevice(DeviceListView.java:43)
at view.DeviceListView.setDeviceList(DeviceListView.java:33)
at view.DeviceListView.lambda$setDeviceList$7(DeviceListView.java:36)
at view.DeviceListView$$Lambda$160/2054192134.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1826358374.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1915503092.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$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/1963387170.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)

第36行是这一行:AnswerMessage answer = tcp.sendRequest(new RequestMessage(RQST_DEVICE_INFO, deviceListView.getSelectionModel().getSelectedItem().toString()));

我希望有人能够帮助我

0 个答案:

没有答案