I'm parsing a bunch of ints from strings that were 'substring-ed' from a simpleDateFormat string. For some reason that I haven't been able to figure out the String monthString keeps coming up NULL, I dont see why.
I have created the string in another function call and when I pass it to the next function the string then becomes NULL
public class MainMenu extends JFrame implements ActionListener {
private JButton start, highscore, help, stoppen;
private int yearNumber, monthNumber, dayNumber, daysInMonth;
private String monthString, yearString, dayString;
private String timeStamp = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime());
public void go(){
setMonthString();
getDayString();
getYearString();
getDayNumber(dayString);
getYearNumber(yearString);
getMonthNumber(monthString);
getDaysInMonth(monthString);
makeThisMonthFolders();
maakComponenten();
maakLayout();
toonFrame();
}
private void makeComponent() {
String timeStamp = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime());
String dayString = timeStamp.substring(0,2);
System.out.println("Today is day " + dayNumber + " of the month");
String monthString = timeStamp.substring(3, 5);
System.out.println("Month string: " + monthString);
start = new JButton("Move Folders"){
{
setSize(150, 75);
setMaximumSize(getSize());
}
};
start.addActionListener(this);
}
private String setMonthString(){
String monthString = timeStamp.substring(3, 5);
if(monthString.substring(0,1) == "0"){
System.out.println(monthString.substring(0,1));
}
/*if(monthString.substring(0, 1) == "0"){
monthString = monthString.substring(1);
}*/
return monthString;
}
public int getMonthNumber(String monthString){
System.out.println(monthString);
monthNumber = parseInt(monthString);
return monthNumber;
}
}
Here is the null return from a test and the error codes thrown:
Today is day 0 of the month
Month string: 07
Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:542)
at java.lang.Integer.parseInt(Integer.java:615)
at com.company.MainMenu.getMonthNumber(MainMenu.java:123)
at com.company.MainMenu.go(MainMenu.java:37)
at com.company.Main.main(Main.java:11)
7
null
ERROR AT 123 references:
System.out.println(monthString);
monthNumber = parseInt(monthString); // this line
return monthNumber;