Question

I have been working on this for hours and can't find the problem by myself or online. I dont know why the first loop does work and the second does not proceed past the first itteration.

File adjacencies = new File(adjacenciesFile);
Scanner adjacenciesScanner = new Scanner(adjacencies);
//idk why this works and the while loop after doesn't 
/*
while(adjacenciesScanner.hasNextLine()){
        System.out.println(adjacenciesScanner.nextLine());
    }
*/

while(adjacenciesScanner.hasNextLine()){
    ArrayList<Country> adjacentCountries = new ArrayList<Country>();
    String[] adjacenciesNames = adjacenciesScanner.nextLine().split(",");

    for(String countryName : adjacenciesNames){
        adjacentCountries.add(this.countries.get(countryName));
    }
    System.out.println(adjacentCountries);
    adjacentCountries.remove(0);
    this.countries.get(adjacenciesNames[0]).addAdjacencies(adjacentCountries);
}

This is the file that I am reading in:

Alaska,Alberta,Northwest Territory,Kamchatka
Alberta,Alaska,Northwest Territory,Ontario,Western United States
Central America,Western United States,Venezuela
Eastern United States,Western United States,Ontario,Quebec
Greenland,Northwest Territory,Ontario,Quebec,Iceland
Northwest Territory,Alaska,Greenland,Ontario,Alberta

There is no exception, it just doesn't run more than once

Was it helpful?

Solution

If you set a break point and run it in debug mode, you should see exactly why it's exiting the loop. Looks fine to me, if anything, you may be getting an exception on your split().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top