Okay this is kind of hard to explain but I'll try my best.
I'm creating a program that reads from a .data file, saves each line of the file into an array list, then the user specifies the building and room number to look for, the program then searches through the whole array list (couple thousand lines) for matches, then with those matches calculates how often those rooms are used using some of the data obtained from the data file.
Now, the problem is that I can get up to the program searching through the array list, but it seems to be doing something incorrectly.
String buildingNum = jTextField2.getText();
String roomNum = jTextField1.getText();
int strDuration = 0;
int totalDuration = 0;
int meetings = 0;
for (int x = 0; x < Global.globalLength; x++) {
if ((buildingNum != "XXXX") && (list.get(x).building != "XXXX") && (list.get(x).room != "XXXX") && (roomNum != "XXXX")) {
int intBuildingNum = Integer.parseInt(buildingNum);
int intRoomNum = Integer.parseInt(roomNum);
int listBuildingNum = Integer.parseInt(list.get(x).building);
int listRoomNum = Integer.parseInt(list.get(x).room);
if (listBuildingNum == intBuildingNum) {
System.out.println("Second STEP WOO");
if (listRoomNum == intRoomNum) {
strDuration = Integer.parseInt(list.get(x).duration);
meetings = list.get(x).days.length();
totalDuration = totalDuration + (meetings * strDuration);
System.out.println(strDuration + " and " + meetings);
System.out.println(" and " + totalDuration);
}
}
}
}
int utilization = totalDuration / 50;
jTextArea1.setText("The room utilization is: " + utilization);
In the data file, there are a few places in which data is entered as XXXXXXXXXXXX
for whatever reason. Because of this, when trying to convert said data into an integer there's a problem (for obvious reasons). So to fix this, I made that odd if
block right after the for
loop so that the program would try not to do so.
However, When running it, I am able to get the program to display the total duration a couple of times before it gives an error that says
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "XXXX"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
Which I THOUGHT I had fixed. Can anyone see why it would still be trying to convert the XXXX
into integers?