2014-04-14 4 views
0

나는 몇 시간 동안이 작업을 해왔으며 스스로 또는 온라인으로 문제를 찾을 수 없습니다. 왜 첫 번째 루프가 작동하고 두 번째 루프가 첫 번째 반복을 지나치지 않는지는 알 수 없습니다. 당신이 중단 점 및 실행을 설정하면왜 내 hasNextLine() 루프는 한 번만 작동합니까?

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 

예외가, 그냥 한 번

+0

루프가 두 번 이상 실행되거나 예외가 있습니까? –

+0

무엇이 인쇄됩니까? 예외가 있습니까? 좀 더 자세한 정보를주세요. –

+0

'addAdjacencies'에 대한 호출을 주석 처리하고 이것이 루프를 차단 해제하는지 확인하십시오. – dasblinkenlight

답변

1

이상이 실행하지 않습니다되어

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); 
} 

내가 읽기하고있는 파일입니다 디버그 모드에서 루프가 종료되는 이유를 정확히 확인해야합니다. 나에게 잘 어울린다. 만약 당신이 split()에 대한 예외를 얻고 있다면.

관련 문제