+ 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?
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.
0
You must Declare The string Outeside of the start methode , then you can asign to it a Value