java - JavaFX: Accessing FXML elements from a second class -
i writing program attempting following:
- take 2 text files , write contents 2 separate textareas
- 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
Post a Comment