I want to get a text from textField and store it in a String ... but when I write this code,my String is missing in Start method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I want to get a text from textField and store it in a String ... but when I write this code,my String is missing in Start method

id.setOnAction(new EventHandler<ActionEvent) { @Override public void handle(ActionEvent event) { String strId = id.getText(); } }); how can I save my text of textField in the String?

22nd Jun 2017, 7:59 PM
SaraBolouri
2 Answers
+ 1
I don't know if you just made a typo here when you posted this or if your actual code looks like what you posted, but it should look more like this: id.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { String strId = id.getText(); } }); or better yet change it to a lambda: id.setOnAction((event) -> { String strId = id.getText(); }); But then you're not doing anything with the variable strId. At least not within its scope. Remember that you're declaring it within a method that's within an anonymous class. So you would need to use it within that method or move its declaration outside of that method to broaden its scope.
23rd Jun 2017, 1:24 AM
ChaoticDawg
ChaoticDawg - avatar
0
You must Declare The string Outeside of the start methode , then you can asign to it a Value
29th Jun 2017, 3:35 AM
Younes Charfaoui
Younes Charfaoui - avatar