title: JavaFX: Service and GUI
body: <p>For a school project, I am programming a little Visualization for a PLC. Therefore I have a mySQL Database which has all the Information. Currently, when I click on a Button the program connects to the Database and gets it Information in an ArrayList. Then it checks the information in the ArrayList and puts Data in a ListView.</p>
  
  <p>The problem is, that I want to let the program do that in a Service. As I said the GUI depends on the ArrayList. And I can't change the GUI in the service because then this Exception appears</p>
  
  <pre><code>  Sep 02, 2016 9:19:02 PM javafx.concurrent.Service lambda$static$488
  WARNING: Uncaught throwable in javafx concurrent thread pool
  java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
      at com.sun.javafx.tk.Toolkit.checkFxUserThread(Unknown Source)
      at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(Unknown Source)
      at javafx.scene.Parent$2.onProposedChange(Unknown Source)
      at com.sun.javafx.collections.VetoableListDecorator.setAll(Unknown Source)
      at com.sun.javafx.collections.VetoableListDecorator.setAll(Unknown Source)
      at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(Unknown Source)
      at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(Unknown Source)
      at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(Unknown Source)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(Unknown Source)
      at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(Unknown Source)
      at javafx.beans.value.WeakChangeListener.changed(Unknown Source)
      at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(Unknown Source)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(Unknown Source)
      at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(Unknown Source)
      at javafx.beans.property.StringPropertyBase.markInvalid(Unknown Source)
      at javafx.beans.property.StringPropertyBase.set(Unknown Source)
      at javafx.beans.property.StringPropertyBase.set(Unknown Source)
      at javafx.beans.property.StringProperty.setValue(Unknown Source)
      at javafx.scene.control.Labeled.setText(Unknown Source)
      at application.Controller$1$1.call(Controller.java:290)
      at application.Controller$1$1.call(Controller.java:1)
      at javafx.concurrent.Task$TaskCallable.call(Unknown Source)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at javafx.concurrent.Service.lambda$null$493(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at javafx.concurrent.Service.lambda$executeTask$494(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>My first Idea was to extract only the SQL stuff in the Service and then get the Data via the Method</p>
  
  <pre><code>service.getValue();
  </code></pre>
  
  <p>But the problem with this is that I don't know when the Service is finished to get the Data, because currently, the data is null. </p>