I'm writing some code that checks a condition in another object in a while loop, and then executes that condition when its met. In this case, I'm waiting for a string to be set to something other than null.
This seems pretty straight forward, but I'm having some weird output. If I put a System.out.println(); statement inside the loop (i.e. thousands of the same line printed to the console), the code exits when its supposed to, continues on, and prints the necesary objects.
However, as soon as I take this System.out.println(); statement out of the while loop (and change nothing else!) nothing gets printed afterwards. Any ideas on why this might be? I've tried to flush it and I've tried manually putting in new lines to each statement. I've even tried simply incrementing a variable (but not printing it) in the while loop (which did not work). I'm kind of at a loss. The code is below (its in its own thread)
public void run(){
System.out.println("Hey kids" + "\n\n");
//int test = 0; //tried this to make it work.
while(gui.directoryName == null){
//this is the problematic loop
//test++;
//System.out.println("Uncomment this to make it work");
}
System.out.println("here" + "\n\n");
parseFiles();
//launchFactory();
}
private void parseFiles() {
System.out.println("here");
String[] files = new File(gui.directoryName).list();
String[] factoryFiles = new File(gui.directoryName).list(new FACTORYFileFilter());
String[] recipeFiles = new File(gui.directoryName).list(new RCPFileFilter());
for(String file: files){
System.out.println("File: " + file + "\n\n");
}
for(String file : factoryFiles){
System.out.println("Factory file = " + file + "\n\n");
}
for(String file : recipeFiles){
System.out.println("Recipe file: " + file + "\n\n");
}
System.out.println("here");
System.out.flush();