title: local variables referenced from a lambda expression must be final or effectively final
body: <p>I have a JavaFX 8 program  (for JavaFXPorts cross platfrom) pretty much framed to do what I want but came up one step short. The program reads a text file, counts the lines to establish a random range, picks a random number from that range and reads that line in for display. </p>
  
  <pre><code>The error is: local variables referenced from a lambda expression must be final or effectively final
          button.setOnAction(e -&gt; l.setText(readln2));
  </code></pre>
  
  <p>I am a bit new to java but is seems whether I use Lambda or not to have the next random line display in <code>Label l</code>, my <code>button.setOnAction(e -&gt; l.setText(readln2));</code> line is expecting a static value. </p>
  
  <p>Any ideas how I can tweak what I have to simply make the next value of the var readln2 display each time I press the button on the screen? </p>
  
  <p>Thanks in advance and here is my code:</p>
  
  <pre><code>String readln2 = null;
  in = new BufferedReader(new FileReader("/temp/mantra.txt"));
  long linecnt = in.lines().count();
  int linenum = rand1.nextInt((int) (linecnt - Low)) + Low;
  try {
      //open a bufferedReader to file 
      in = new BufferedReader(new FileReader("/temp/mantra.txt"));
  
      while (linenum &gt; 0) {
          //read the next line until the specific line is found
          readln2 = in.readLine();
          linenum--;
      }
  
      in.close();
  } catch (IOException e) {
      System.out.println("There was a problem:" + e);
  }
  
  Button button = new Button("Click the Button");
  button.setOnAction(e -&gt; l.setText(readln2));
  //  error: local variables referenced from a lambda expression must be final or effectively final
  </code></pre>