What I am doing here is that I want to separate a string into three different substrings. The context here is that there is a date in the MM/DD/YYYY or M/D/YYYY format and that I want to separate the three contents of the string so I can display them. What I have done here is to use the substring method and take the indexes of the string with the "/"
and convert the substrings into integer values for other uses. What I have done is I took the user input for the date and convert it to a string, then there are three methods that take the substring of the string into three different parts(one for year, one for month, and so on). Then the values are put into text values for the program to be displayed. Whenever I run the program, it gives me an error stating: Exception in thread "JavaFX Application Thread" java.lang.NumberFormatException: For input string: "Text[text="1"
. I tried searching the internet for answers but all I came across to was this What is a NumberFormatException and how can I fix it? and I am still confused on what is wrong with my program.
//for example purposes we will use 12/05/2005 as the example user input
Text input= new Text();
userInput.setText(input.getText());
String stringInput= userInput.toString();
String monthString = stringInput.substring(0,stringInput.indexOf("/"));
String dayString = stringInput.substring(stringInput.indexOf("/"),stringInput.indexOf("/") );
String yearString = stringInput.substring(stringInput.indexOf("/"));
int monthInt= Integer.parseInt(monthString);
int dayInt= Integer.parseInt(dayString);
int yearInt= Integer.parseInt(yearString);
Text monthPrint = new Text("months:" + monthInt);
Text dayPrint = new Text("days: " + dayInt);
Text yearPrint = new Text("years: " + yearInt);
//the expected printout would be
/*
months: 12
days: 5
years: 2005
*/