java - JavaFX: Accessing FXML elements from a second class -


i writing program attempting following:

  1. take 2 text files , write contents 2 separate textareas
  2. write these separate areas simultaneously using multithreading, runnable interface

i have created "myrunnable" class:

public class myrunnable implements runnable {      @fxml     private textarea textfield;      public myrunnable() throws ioexception {     }      public void run() {          string firstfilename = "test.txt";         file infile = new file(firstfilename);         scanner in = null;         try {             in = new scanner(infile);         } catch (filenotfoundexception e) {             e.printstacktrace();         }         while (in.hasnextline()) {             textfield.appendtext("hello");             textfield.appendtext("\n");         }     } } 

my controller class has 1 method

public void main() throws ioexception {     runnable r = new myrunnable();     thread t = new thread(r);     t.start(); } 

intellij tells me textfield never assigned, , when run main program, , click button calls main() null pointer exception on following line.

textfield.appendtext("hello"); 

how accomplish want accomplish?

could move textfield controller class , pass argument runnable?


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -