0

I have a Java FXML application I'm making in NetBeans, so far everything is working as intended but as I am starting to polish everything and making it more user frinedly I came across a problem with this particular code:

@FXML
private Label differenceResultsLabel;
@FXML
private Label responseTimeResultsLabel;

public boolean checkForResponseTime(double[] responseTimeArray)
{
    int arrayLength = responseTimeArray.length;
    double maxThreshold = Double.parseDouble(maxResponseTime.getText());
    for (int i=0; i < arrayLength ; i++)
    {
        if (responseTimeArray[i] > maxThreshold)
        {
            System.out.println("Response Time beyond threshold!");
            responseTimeResultsLabel.setTextFill(Color.RED);
            responseTimeResultsLabel.setText(Arrays.toString(responseTimeArray));
            return false;
        }
    }
    System.out.println("All response times OK");
    responseTimeResultsLabel.setTextFill(Color.GREEN);
    responseTimeResultsLabel.setText(Arrays.toString(responseTimeArray));
    System.out.println("Hello?");
    return true;
}

Note that the labels are already fx:id'd in the FXMLDocument.fxml file. However, when I run the program the labels dont change (even though I get the other lines (Hello? and All response times ok).

Here's the output NOTE: I DELETED A BUNCH OF SYSTEM.OUTPRINTLN's TO MAKE IT MORE READABLE :

Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
    Time logged: 14.178
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
    2017-04-25T12:35:07.230is above target temp for channel 0
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
    2017-04-25T12:35:07.548is above target temp for channel 1
    2017-04-25T12:35:07.884is above target temp for channel 2
    2017-04-25T12:35:08.219is above target temp for channel 3
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
    2017-04-25T12:35:07.548is above target temp for channel 4
    2017-04-25T12:35:07.548is above target temp for channel 5
    2017-04-25T12:35:07.884is above target temp for channel 6
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
    2017-04-25T12:35:07.884is above target temp for channel 7
    The updated indexes for initial findings are: [7, 8, 9, 10, 8, 8, 9, 9, 0]
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
    2017-04-25T12:35:16.777is above target temp for channel 0
    2017-04-25T12:35:14.477is above target temp for channel 1
    2017-04-25T12:35:19.092is above target temp for channel 2
    2017-04-25T12:35:19.092is above target temp for channel 3
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
    2017-04-25T12:35:13.488is above target temp for channel 4
    2017-04-25T12:35:13.153is above target temp for channel 5
    2017-04-25T12:35:16.777is above target temp for channel 6
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
    2017-04-25T12:35:14.477is above target temp for channel 7
    The updated indexes for final findings are: [36, 29, 43, 43, 26, 25, 36, 29, 0]
    Channel 1 had a response time of: 9.547
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
    Channel 2 had a response time of: 6.929
    Channel 3 had a response time of: 11.208
    Channel 4 had a response time of: 10.873
    Channel 5 had a response time of: 5.9399999999999995
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
    Channel 6 had a response time of: 5.605
    Channel 7 had a response time of: 8.893
    Channel 8 had a response time of: 6.593
    The updated response times are: [9.547, 6.929, 11.208, 10.873, 5.9399999999999995, 5.605, 8.893, 6.593]
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
    Max RT is: 11.208. Min RT is: 5.605
    Percent difference is 0.6665080592398738%. Max percent difference is: 0.5
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.doStopTest(FXMLDocumentController.java:297)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:785)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
    Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
    Percentage test is: false
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
    All response times OK
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.doGet8Results(FXMLDocumentController.java:352)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:786)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
    Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
    Response Time test is: true
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.checkPercentage(FXMLDocumentController.java:460)
        at at.qcresponsetime.FXMLDocumentController.doGet8Results(FXMLDocumentController.java:387)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:786)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
    Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.writeRTLabel(FXMLDocumentController.java:291)
        at at.qcresponsetime.FXMLDocumentController.checkForResponseTime(FXMLDocumentController.java:416)
        at at.qcresponsetime.FXMLDocumentController.doGet8Results(FXMLDocumentController.java:389)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:786)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
    Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.setFail(FXMLDocumentController.java:563)
        at at.qcresponsetime.FXMLDocumentController.doGet8Results(FXMLDocumentController.java:397)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:786)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
    Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.setFail(FXMLDocumentController.java:564)
        at at.qcresponsetime.FXMLDocumentController.doGet8Results(FXMLDocumentController.java:397)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:786)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
  • @James_D Hi James, thanks for the links, I'm going over them and some documentation. I am having issues (tried googling but cant find a consise answer). How do I know which is my FX application thread? how do I know what method is running on what thread? I know Swift (x-Code) has a tool that lets you see this but I can't find this on netbeans – David Boydston Apr 25 '17 at 20:11
  • Generally, methods will execute on the thread on which you cause them to be executed (i.e. the same thread as the method from which you call them), unless you explicitly start a new thread or use a class that starts one for you. For methods that are invoked by a framework (e.g. methods invoked by JavaFX), you need to read the docs, but basically the `start` method, event handlers, and `Runnable`s you pass to `Platform.runLater(..)` are invoked on the FX Application Thread. – James_D Apr 25 '17 at 20:14
  • @James_D That's kind of what's confusing me, I basically have been reading lots of examples to come up with the code I have, while I understand everything in the code there are some "overall" features I dont understand, for example my code is all inside public class FXMLDocumentController implements SerialPortEventListener{}. ALL METHODS are inside that, some methods (action-buttons) were automatically created with (at)FXML before declaration, I dont know what this means. and there's only one method (the event listener) that has (at)Override, which again I dont FULLY understand. – David Boydston Apr 25 '17 at 20:21
  • @James_D, from what I said before, when you say about the start method, or when other pages call out the main method, I dont have any of those which is what confuses me – David Boydston Apr 25 '17 at 20:22
  • "Which thread" basically has nothing to do with "which class". Multithreading is an advanced topic and you should not attempt to do it until you have understood the basics. (OT: a JavaFX application essentially starts execution with the `start()` method. You have one somewhere.) – James_D Apr 25 '17 at 20:24

0 Answers0