I'm trying to ask the user for a file to use. If the file is found then the program continues, but if the file is not found the user is asked to enter the filename again and again until it's found. I assume I could do it with a loop, but I'm unsure of the condition to test for the file not found.
The problem I run into now is a Null pointer exception. If I surround the loop with a try/catch it works ok, but it only runs once. I'm not sure if I'm missing something or whether there's a problem with the logic.
static File file; // class variable File file = new File(filename); // local variable You declared the variable file in two locations. By doing so, the local one is used within the curl brackets of do...while loop. This is called shadowing. Once it is out of curl brackets, the class variable file referencing to a null object is used.