import java.util.Scanner; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; public class CountryPopulationReverse{ public static void main(String args[])throws FileNotFoundException { Scanner in = new Scanner(System.in); Scanner FileIn; FileReader inputFile; String population, country; int checkNum; PrintWriter output; boolean good = false; //Try catch for valid file goes here while(!good) { try { System.out.print("Input file: "); String inputName = in.nextLine(); inputFile = new FileReader(inputName); FileIn = new Scanner(inputFile); good=true; }catch ( FileNotFoundException e){ System.out.println("File not found."); } } System.out.print("Output file: "); String outputName = in.nextLine(); output = new PrintWriter(outputName); try { while(FileIn.hasNextLine()) { country = FileIn.next(); population = FileIn.next(); checkNum = Integer.parseInt(population); if(checkNum<=5) throw new BadDataException("Population (" + checkNum + ") is too low."); if(checkNum>2000000000) throw new BadDataException("Population (" + checkNum + ") is too high."); } } catch (BadDataException e) { System.out.println("Bad Data: " + e.getMessage());} catch (NumberFormatException e) { System.out.println(e.getMessage());} output.close(); } }
CountryPopulationReverse.java:40: error: variable FileIn might not have been initialized while(FileIn.hasNextLine()) ^ 1 error
Everytime I move some code somewhere else to get rid of the error then another one pops up it is very frustrating.