0

I have the following timer:

Timer t = new Timer();
        t.schedule(
                new TimerTask() {

        @Override public void run(){
              Firebase ref = new Firebase("https://fsn1xtvlo0z.firebaseio-demo.com/Move/connection");
              ref.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot snapshot) {
                        String connected = String.valueOf(snapshot.getValue());
                        /*if (connected.equals("a"))
                            label8.setText("Connected to Phone");*/
                        if (connected.equals("c"))
                            label8.setText("Phone is not connected");
                    }
                    @Override
                    public void onCancelled(FirebaseError firebaseError) {
                        label8.setText("No Connection");
                    }
                });
              ref.setValue("c");              
          }
        }, 0, 5000);

snapshot is the JSON "\"a\"" or "c". I get an IllegalStateException when comparing the string which has the value of snapshot to "a" or "\"a\"" but not when comparing it to "c". How can that be?

EDIT: The Exception is:

Exception in thread "FirebaseEventTarget" java.lang.IllegalStateException: Not on FX application thread; currentThread = FirebaseEventTarget
    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 Main$1$1.onDataChange(Main.java:54)
    at com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:56)
    at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
    at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
  • What was the stacktrace ? – Dici May 07 '16 at 19:12
  • are you sure exception is thrown on comparing strings? `String#equals()` doesn't throw any exception. – Alex Salauyou May 07 '16 at 19:13
  • Ok, better with the stacktrace. This has nothing to do with your strings apparently. Can you give us more context ? Are you developng a JavaFX GUI or are you using a JavaFX class by mistake ? – Dici May 07 '16 at 19:15
  • 3
    seems it complains that you're trying to access view element (`label8.setText()`) in a wrong thread. In second case, you have no exception because `equals()` returns `false` and *if* block is not entered. – Alex Salauyou May 07 '16 at 19:17
  • But the if block must have been entered cause the UI was changed to "Phone is not connected". – user6287736 May 07 '16 at 19:25

0 Answers0