title: TimerTask can't update the JavaFX Label text
body: <p>I have a <a href="https://dl.dropboxusercontent.com/u/34696560/KoBSON/PDFDownloader/layout_normal.jpg" rel="nofollow noreferrer">fairly simple JavaFX GUI application</a> which has an label that shows how much time is left until a certain action starts. To achieve this, I've created a DownloadTimer class as shown below:</p>
  
  <pre><code>public class DownloadTimer(){
      private int minutes;        
      private int seconds;
      private Timer innerTimer = new Timer();
      private TimerTask innerTask;
      private boolean isActive;
  
      public DownloadTimer(int minutes, int seconds) {
          if (seconds &gt; 60) {
              int minToAdd = seconds / 60;
              this.minutes = minutes;
              this.minutes += minToAdd;
              this.seconds = seconds % 60;
          } else {
              this.minutes = minutes;
              this.seconds = seconds;
          }
      }
  
      public void start() {
          innerTask = new TimerTask() {
              @Override
              public void run() {
                  isActive = true;
                  System.out.println(getTime());
                  if (seconds == 0 &amp;&amp; minutes &gt; 0){
                      minutes -= 1;
                      seconds = 59;
                  } else if (seconds == 0 &amp;&amp; minutes == 0){
                      isActive = false;
                      innerTimer.cancel();
                      innerTimer.purge();
                      System.out.println("DownloadTimer DONE");
                  } else {
                      seconds -= 1;
                  }     
              }
          };
          innerTimer.scheduleAtFixedRate(innerTask, 0, 1000);
      }
  }
  </code></pre>
  
  <p>And then, I'm creating the DownloadTimer object and starting the countdown from my Main (JavaFX) class:</p>
  
  <pre><code>/* 
      code omitted for better readability 
  */
  
  downloadTimer = new DownloadTimer(0, 5);
  
  // label gets the .getTime() value, which returns a formatted String like "00:05", "00:04", etc.
  lblTimer.setText( downloadTimer.getTime() );
  
  // start the countdown
  downloadTimer.start();
  
  // create a new timer which checks if the downloadTimer is still counting
  final Timer timer = new Timer();
  TimerTask timerTask = new TimerTask(){
      @Override
      public void run(){
          if (downloadTimer.getIsActive() == false){
              timer.cancel();
              timer.purge();
              System.out.println("GUI timer DONE");
          } else {
              // if it's still running, then continuously update the label's text
              lblTimer.setText( downloadTimer.getTime() );
              // this is where I get the error described below
          }
      }
  };
  // repeat after 1000ms
  timer.scheduleAtFixedRate(timerTask, 0, 1000);
  </code></pre>
  
  <p>The problem I'm encountering with this is that I can't set the label text with <code>lblTimer.setText( downloadTimer.getTime() );</code> from the Main class, and the error I'm getting is <code>TimerThread.run() line: not available [local variables unavailable]</code> as <a href="https://dl.dropboxusercontent.com/u/34696560/KoBSON/PDFDownloader/timer.jpg" rel="nofollow noreferrer">seen here</a>. </p>
  
  <p>I've read about <a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html" rel="nofollow noreferrer">ScheduledThreadPoolExecutor</a> and <a href="https://stackoverflow.com/questions/409932/java-timer-vs-executorservice/">Java Timer vs ExecutorService</a>, but I'm curious if this can be done using two separate Timers and TimerTasks. Any help and/or tips would be greatly appreciated.</p>